Wednesday, November 3, 2010

Controller: Carriers

Controllers provide the functionality of your application. Controllers are named plural and "controller" is explicitly listed in the name.

Create /app/controllers/carriers_controller.php
<?php
class CarriersController extends AppController {
    var $name = 'Carriers';
    var $scaffold;
}
?>
If the controller is using a model other than, or in addition to, the one with the same name as its name, you can access that model in one of two ways.
  1. Add var $uses = array('Carrier', 'Other');
  2. Access the other model directly in code via $this->Carrier->Other...
Adding the Carrier model in the Carriers controller in option 1 is unnecessary since it is automatic, but is listed only for clarity.

The variable $scaffold turns on automated scaffolding for testing and viewing of database data. After testing is complete, ensure to remove the scaffolding line to prevent unauthorized access. If you test with scaffolding, any defined methods will override the scaffolding.

Upload the file and browse to http://drug-ed.com/carriers to verify it works, then add a few carriers.
NameExtension
Verizon PCSvtext.com
AT&T PCStxt.att.net


Observe that since there is a defined relationship between Carriers and Users the actions "New User" and "List Users" are available on the Carriers page. Since there is no Users controller the links don't work yet.

No comments:

Post a Comment