Skip to content
wilburhimself edited this page Mar 29, 2011 · 2 revisions

Controller or actions form the basis of interaction with the Views and the Models of our applications.

By default Controllers live in the controllers folder. Each Model resides in a file named after the model's class in lowercase.

The simplest code for a controller is:

class Foo extends Controller {
    public function __construct() {
        parent::__construct();
    }

    public function index() {}
}

This index function will be called upon a request to http://website.com/foo

Actions

All public methods in the controller are considered actions, so if you want an action for http://website.com/foo/create you would create a public method called create on the controller.

Each action automatically, unless specified or unless a redirect exists, will include and compute a view. Each controller has a folder for it's views in the views folder. For example the views for the Foo controller will be in views/foo/*

Rendering a message instead of a view

If you want to break the auto loading of the view and render a message or text instead you can call the render method on the Controller as such:

$this->render('text', 'this is a message');

Which will print a message and dont load a view or a layout for this action.

Clone this wiki locally