CakePHP: controller without model

Having a controller without a model in CakePHP is very simple: just declare the variable $uses=null in the controller.

class MycoolsController extends AppController{
var $name="Mycools";
var $uses = null;
...
}

Advertisements

4 thoughts on “CakePHP: controller without model

  1. Well, I tried this one. But what if, i want to use external models and i _have_ to use $uses? Such as $uses = array(‘Html’, ‘Javascript’); ?

  2. mfkabir says:

    ok
    this is my controller

    class BooksController extends AppController{
    var $name=’Books’;
    var $uses=array();

    function index($id=0){
    $this->set(‘page_heading’,’Packt Book Store’);
    $books = array(
    ‘0’=>array(
    ‘book_title’=>’Object Oriented Programming with PHP5’,
    ‘author’=>’Hasin Hayder’,
    ‘isbn’=>’1856486656’,
    ‘release_date’=>’December 2010’
    ),
    ‘1’=>array(
    ‘book_title’=>’Building Websites with Joomla! 1.0’,
    ‘author’=>’Hagen Graf’,
    ‘isbn’=>’1904811949’,
    ‘release_date’=>’March 2006′
    )
    );
    $id=intval($id);
    if($id=count($books)){
    $id=0;
    }
    $this->set($books[$id]);
    $this->pageTitle=’Welcome to the PACKT book store!’;
    }
    }

    and this is my view:

    Author:
    ISBN:
    Release Date:

    but when i want to access books/1 url an error shows.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s