Jump to content

cakephp about home.ctp


delta37

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)) {
        $this->redirect('/');
    }
    
    $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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.