With my new job I have been using Solar a lot and learning something new at every corner. This is my attempt to document some of those things I run into that may not be in the manual yet, may not be clear or may just be useful to all.

Your building your application and you need to ensure every controller has access to the proper classes, layouts and basic properties. One common way you will see this done is general setup within the constructor of each class but this requires a lot of code duplication.

Another way can be done below

abstract class Your_App_Base extends Solar_Controller_Page {
    // Set the default action you want to be used
    protected $_action_default = 'default';
    // Set the default layout you want to be used
    protected $_layout_default = 'default';

    protected function _setup() {
        // Do anything you need done every time your controllers are called
    }
}

Now in your controllers instead of extending Solar_Controller_Page you extend Your_App_Base. A common use for this is as follows

abstract class Your_App_Base extends Solar_Controller_Page {
    protected function _setup() {
        // register a Solar_Sql object if not already
        if (! Solar_Registry::exists('sql')) {
            Solar_Registry::set('sql', Solar::factory('Solar_Sql'));
        }

        // register a Solar_User object if not already.
        // this will trigger the authentication process.
        if (! Solar_Registry::exists('user')) {
            Solar_Registry::set('user', Solar::factory('Solar_User'));
        }
    }
}

The above code ensures all your controllers have proper access to sql,user and authentication. Other suggestions for this would be to put in some pre-authorization making sure various areas where properly protected based on user settings.

abstract class User_App_Base extends Solar_Controller_Page {
    protected function _setup() {
        // User_App_ = 9 characters
        $area = substr(get_class($this),9);
        // You can now use $area for some sort of pre auth to make sure the user
        // is allowed to access the area you are in
    }

Comments

Hiya --

Thanks for the writeup!

This part ...

        // User_App_ = 9 characters
        $area = substr(get_class($this),9);

... might be  $area = $this->_controller; instead. The $_controller property has the added benefit of having been set from the front controller, which means that you'll get the value of the static route that led to the page controller, if its name was different from the page controller itself. (Hope that made sense. :-)

-- pmj