delta37 Posted February 25, 2009 Share Posted February 25, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/146827-cakephp-about-homectp/ Share on other sites More sharing options...
fabrydesign Posted March 6, 2009 Share Posted March 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146827-cakephp-about-homectp/#findComment-777848 Share on other sites More sharing options...
OnePlus Posted March 23, 2009 Share Posted March 23, 2009 Haven't gone into the page controller but I will look into this for my ongoing personal project Quote Link to comment https://forums.phpfreaks.com/topic/146827-cakephp-about-homectp/#findComment-791581 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.