Using a CakePHP controller without a model

Published by Subhas Fagu on 21/09/09 09:16:29
Last edited on 21/09/09 09:38:20

Sometimes you just want to make a simple controller without an associated model or table. CakePHP makes this very easy while showing its flexibility.

CakePHP uses the variable $uses to associate a controller to a model, by default it uses the singular name of the controller or the $name variable.

Below is an example of a controller without any models attached.

 

class WithoutModelsController extends AppController{
var $name="WithoutModels"
var $uses = null;  

 

Here we have a controller that uses other models but it's own.

 

class DifferentModelsController extends AppController{
var $name=" DifferentModels "
var $uses = array('Event','Photo','Post');

 

This is great as it allows us to create a simple controller to serve up static contents, or even a report controller that uses data from other models.

About the Author

Subhas Fagu is an energetic person who you will never catch doing the same thing twice…unless it’s working. He’s always engaged in new concepts, frameworks, operating systems, applications, you name it and you’ve got a conversation. Being a founder of Techlicity Ventures, he's been a key in the business and technical development of all previous and upcoming projects. Subhas contributes a wide variety of perspectives to all projects to ensure risk coverage and smooth deployment.

Bookmark and Share
Blog Widget by LinkWithin
blog comments powered by Disqus

Valid XHTML 1.0!