Jump to content

cakephp about home.ctp


delta37

Recommended Posts

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

  • 3 weeks later...

Archived

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.