==================== Minimal Application Skeleton ==================== ----------------------- Your Directory Location ----------------------- Because Solar is geared toward distributing applications, you need to create your own "vendor" ("master" or "channel") directory where your classes will be stored. This directory name will be the prefix on all your class names. It can be anywhere in the file system. {{code: bash $ mkdir /home/username/Vendor }} -------------------- Config and Front Controller -------------------- Edit Solar.config.php to recognize your vendor directory (along with the Solar directory) for page controllers. Remember, for security reasons, your config file should not be in the document root. {{code: bash $ cd /path/to/config $ mate Solar.config.php }} {{code: php $config = array(); // ... $config['Solar_Controller_Front']['classes'] = array( 'Solar_App', 'Vendor_App', ); // ... return $config; }} Also, make sure the bootstrap script has the Vendor directory in the include_path along with Solar itself. {{code: bash $ cd /home/username/public_html $ mate index.php }} {{code: php // Path to PEAR libraries, where Solar is installed, // **and** to the Vendor PHP libraries. set_include_path('/home/username/pear/php:/home/username'); // Windows folks should use a "\" and ";" separators // set_include_path('c:\path\to\pear;c:\home\username'); // You could also use something like the following to be OS-independent: // set_include_path(realpath('./relative/path/to/Solar') . PATH_SEPARATOR . realpath('.')); // Load and start Solar // ... }} -------------------- App Directory Setup -------------------- In general, your vendor library should be structured like the Solar library. Since we're doing an application skeleton, we'll need an "App/" directory. {{code: bash $ cd /home/username/Vendor $ mkdir App }} The Vendor directory now looks like this. Vendor/ App/ We'll call our application "Example"; it needs a directory, and subdirectories for its locale files, view files, etc. {{code: bash $ cd /home/username/Vendor/App $ touch Example.php $ mkdir Example $ mkdir Example/Helper $ mkdir Example/Layout $ mkdir Example/Locale $ mkdir Example/View }} The Vendor directory now looks like this. Vendor/ App/ Example.php Example/ Helper/ Layout/ Locale/ View/ -------------------- Page Controller and Action -------------------- Edit your Example.php page controller to make it extend [[Class::Solar_Controller_Page | ]]; give it a default action of 'index', a view-variable of 'output', and a method for the 'index' action. {{code: bash $ cd /home/username/Vendor/App $ mate Example.php }} {{code: php Solar::autoload('Solar_Controller_Page'); class Vendor_App_Example extends Solar_Controller_Page { protected $_action_default = 'index'; public $output = ''; public function actionIndex() { $this->output = "I am the vendor example"; } } }} -------------------- View -------------------- Now create the related view for the index action. {{code: bash $ cd /home/username/Vendor/App $ mate Example/View/index.php }} {{code: html Skeleton App

escape($this->output) ?> }} Now you should be able to browse to http://127.0.0.1/index.php/example/ and see some output. -------------------- Locale -------------------- Create a locale file for US English in the `Locale/` directory: {{code: bash $ cd /home/username/Vendor/App $ mate Example/Locale/en_US.php }} {{code: php return array( 'TEXT_EXAMPLE' => 'I am a translated vendor example', ); }} Now edit actionIndex() to use a locale key instead of a hard-coded string ... {{code: bash $ mate Example.php }} {{code: php public function actionIndex() { $this->output = 'TEXT_EXAMPLE'; } }} ... and edit your view file to translate that key with the [[Class::Solar_View_Helper_GetText | getText() helper]]. {{code: bash $ mate Example/View/index.php }} {{code: html Skeleton App

getText($this->output) ?> }} Now when you browse to http://127.0.0.1/index.php/example/ you will see the translated output. If you add other locale files, such as es_ES.php, and use [[Solar_Locale::setCode() | Solar::$locale->setCode()]] to change locale codes, those translations will appear instead. -------------------- Layout -------------------- Notice that our view script has more to it than just the "core" page content (the $this->output portion). Normally you will want to be able to use the same header and footer portions across all actions in your applications. Let's create a "layout" file to do that for us. Create a basic layout file called "main.php": {{code: bash $ cd /home/username/Vendor/App $ mate Example/Layout/main.php }} {{code: html Skeleton App Layout

Skeleton Application

layout_content; ?> }} Now go back and edit your view script so that it only generates the bare minimum of output: {{code: bash $ mate Example/View/index.php }} {{code: html

getText($this->output) ?>

}} Finally, tell your page-controller class what layout to use by setting the $this->_layout property. {{code: bash $ mate Example.php }} {{code: php Solar::autoload('Solar_Controller_Page'); class Vendor_App_Example extends Solar_Controller_Page { protected $_layout_default = 'main'; protected $_action_default = 'index'; public $output = ''; public function actionIndex() { $this->output = 'TEXT_EXAMPLE'; } } }} Now when you browse to http://127.0.0.1/index.php/example/ you will see the new page with a heading, and the translated output from the action. All other views in your page-controller will use the same layout, unless you change the $this->_layout property to a different layout. (To turn off layout use, just set $this->_layout_default to an empty value.)