Cakephp provides number of core components such as Session,cookie ,email etc. Component extends the object class. It allow us to reuse the code and makes our controller code clean. Use camelcase naming convention while creating component.All components suffixed with 'component' .
class mycustomComponent extends Object {
function myfunc() {
}
}
The component file is stored under app/controllers/components. Next step is to include component inside controllers So that cakephp know that it exists.
class mycustomController extends AppController {
var $components = array('Mycustom');
}
Next step is to call a component method within a controller.
class mycustomController extends AppController {
var $components = array('Mycustom');
function search() {
return $this->Mycustom->myfunc();
}
}
0 Comment(s)