1.7. Basic Application Setup

Let's prepare our application class for something more sophisticated. We'll need a series of properties for later, and a method to do some preliminary setup work for us.

Change to the SYSTEM/source/acme/Acme/App/ directory and open the Blog.php page controller class file. (In this example we use the vim editor, but you can use anything you like.)

$ cd SYSTEM/source/acme/Acme/App/
$ vim Blog.php

Add the following PHP code at the top of the class, above the actionIndex() method.

<?php
    protected $_action_default = 'index';

    protected $_model;

    public $list;

    public $item;

    public $form;

    protected function _setup()
    {
        parent::_setup();
        $this->_model = Solar_Registry::get('model_catalog');
    }

Some brief explanation of the properties is in order:

  • The $_action_default property defines the default action when none is specified in the URI.

  • The $_model property will hold a reference to the registered Solar_Sql_Model_Catalog object. The model catalog retains model class instances for common use by the whole Solar system.

  • The $list property is the list of records found when browsing blog articles. It will be an empty array when no records exist, or an Acme_Model_Blogs_Collection object when records are found.

  • The $item property is a single record for reading, editing, or adding a blog article. It will be a null when no record exists, or an Acme_Model_Blogs_Record object when one is found.

  • The $form property is a Solar_Form object for a blog article. Solar_Form objects are "hints" to the view on how to render a form.

The _setup() method uses the Solar_Registry to lazy-load a reference to the model catalog. The entry is defined in the default config file as $config['Solar']['registry_set']['model_catalog'] at SYSTEM/source/solar/config/default.php, which itself is included by SYSTEM/config.php (As noted above, the model catalog retains model class instances for common use by the whole Solar system.)



Local