Jump to content

cakephp about home.ctp


Recommended Posts

how do I use models like category, user, product in the home.ctp?


Do I have to modify the pages_controller under the cake/lib?

Do I create a new pages_controller?

or is it better to just route the homepage to another view/controller?


any help appreciated

Thanks in advance! ;D

Link to comment
Share on other sites

  • 2 weeks later...

You'll need to add some code to the pages_controller.php file. If you don't have one in your app directory, you can find it somewhere in the cake directory and copy it over. Then look at what is in there and add whatever needs to be added from the code below:

// app/controllers/pages_controller.php

... // The default code
function display() {
    $path = func_get_args();
    if (!count($path)) {
    $count = count($path);
    $page = $subpage = $title = null;

    if (!empty($path[0])) {
        $page = $path[0];

        if ($page == 'home') { // IF HOME PAGE
            $Post = ClassRegistry::init('Post'); // Add Post Class
            $posts = $Post->find('all');	 // Using the class
    if (!empty($path[1])) {
        $subpage = $path[1];
    if (!empty($path[$count - 1])) {
        $title = Inflector::humanize($path[$count - 1]);
    $this->set(compact('page', 'subpage', 'title'));
    $this->render(join('/', $path));


I'm not sure if this is the best way to do it, but it works.

Link to comment
Share on other sites

  • 3 weeks later...


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.