5.2. Location of Views and Layouts

Chapter one provided a basic introduction to how a controller's action method displays its output in a view script of the same name. To review:

Given the URL http://localhost/blog/read/1 ...

  • blog is the controller

  • read is the action

  • 1 is a parameter (multiple params may be passed)

This maps to ...

  • Acme_App_Blog::actionRead(1) in SYSTEM/source/acme/Acme/App/Blog.php

Which outputs to ...

  • SYSTEM/source/acme/Acme/App/Blog/View/read.php

Solar expects to find view scripts in predefined locations. The default directory structure for the Acme vendor with a single blog application looks like the following:

Acme/
        App/
            Blog/
                Layout/
                Locale/
                Public/
                View/
            Blog.php
        Controller/
            Bread/
                Layout/
                Locale/
                Public/
                View/
            Page/
                Layout/
                Locale/
                Public/
                View/
            Bread.php
            Page.php
        Model/
        Sql/
        Filter.php

It should be reasonably obvious from this structure where views and layouts are expected to be found. The blog application expects to find its views and layouts in SYSTEM/source/acme/Acme/App/Blog/View and SYSTEM/source/acme/Acme/App/Blog/Layout respectively. That is straighforward enough, however; if you open the SYSTEM/source/acme/Acme/App/Blog.php file in your favorite editor, you will notice that the Acme_App_Blog class extends Acme_Controller_Page. This is important because it influences the class stack; the hierarchy where Solar looks for files. In this case, Solar first looks for views in SYSTEM/source/acme/Acme/App/Blog/View, and if it doesn't find the required view there, it then looks in SYSTEM/source/acme/Acme/Controller/Page/View. The same goes for layouts. Keep this in mind as you proceed through this chapter.



Local