07. Models
Model in the MVC
The engines folder contains folders named after the controller with controller.php within and a views folder housing all the views, but there is no model.php file. This is because in typical MVC models the model files are usually independent of the controller, such that multiple controllers can access a single model. for this reason there is a model folder in /path/to/zedek/models/. Any file entered here with a class definition and within the same namespace will be accessed by all controllers by simply calling on that class. Lets illustrate this.
Create a new file and call it anything really, but for this purpose lets call it school.php and save to the models/ folder. Now enter the following content:
<?php namepspace zf; class Teacher { function employ($name){ return $name." has been employed"; } } Now return to the engines folder and create a new controller, by first creating a folder foo/ and within it controller.php. In this file enter the following content:
<?php namespace ; class CController extends ZController{ function bar(){ $cobham = new Teacher; print $cobham->employ("Cobham Zuma"); } } if you browse now to yoursite/foo/bar you should see the message on the screen Cobham Zuma has been employed.
Its that simple. The class immediately becomes available to all controllers.