Application:views
From Surebert wiki
Overview
Views are the publically viewable part of your web application. They display the data from the Framework:models using .view (php) files. The $this of .view templates is the Controller which called the file.
- In the surebert framework views are found in /private/views
- View template paths should be object/action when possible. It does not necessarily have to correspond one to one with model/method but if possible it is ideal.
.view templates
- View templates are what the end user sees.
- They are stored as .view files. *:E.g. /views/dog/jump.view would be served at http://yoursite.com/dog/jump
- The "$this" of each .view template is either the custom Controller that handles the request. /dog/jump would be handled by DogController or IndexController by default if the custom DogController does not exist.
- Any properties of the Controller are accessible in the .view file by referencing $this.
- The view templates used to display information requested and should be most markup with some PHP sprinkled in. If you have a lot of PHP processing in a .view template, you should consider refactoring and moving that code into the Controller for that .view or into the models that the .view is referencing. The only time the .view template should contain a significant amount of PHP processing is when that .view is using code that is shared absolutely no where else.
- There should never be SQL requests in the .view templates. All sql querying should be done in the models, with occasional view specific calls, e.g. caching, etc done in the Controller itself.
- If a requested .view template is not found then, the handling Controller's not_found() method is called. By default sb_Controller throws a 404 error in its not_found() method and displays the contents of /errors/404.view, you can override this be defining your custom Controller's not_found() method.
- View templates must have a .view extension, but also may have additional “real” extension before the .view /private/views/scripts/app.pages.js.view is totally legal would be served at http://site/scripts/app.pages.js. That way you can use PHP in you javascript, css, etc. Make sure to send the appropriate Content-type headers header("Content-type: text/css");
Including Other Views
If you want to load another .view template in the same domain use the following This would load the sleep.view in /views/dog if you called it from /views/dog/index.view. when you render another template this way, it does not reinstantiate the Controller.
php code
echo $this->render_view('/dog/sleep');
For more information about rendering other views inside the view you are within see, or passing arguments to other views for rendering, see Gateway::render_request($request)