Re: Pagination in 1.2 error :(
Very strange, I used var $uses with many models and the paginator works very well. I dont think it is the reason of the error. Can you send your code? Titang --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Pagination in 1.2 error :(
Yes offcourse here is my controller: articles_controller.php ?php /** * Article controller * All article logic is used here * * @author Chris de Kok * @version 1.0 * @package articles * */ class ArticlesController extends AppController { // Name var $name = 'Articles'; // Pagination settings var $paginate = array('limit' = 15, 'page' = 1); // Helpers var $helpers = array('Html','Form', 'Time'); // Load other models var $uses = array('Tag', 'Menu'); /** * This function shows a list of all articles * it will be called on /article or /article/index * */ function index() { $this-set('articles', $this-paginate('Article')); } /** * Function to show one article * parameter is id of the article * * @param integer $id */ function view($slug = null) { $article = $this-Article-findBySlug($slug); $this-set('article', $article); } /** * Function to save an article to the database * */ function add() { if (!empty($this-data)) { // Check if data has been saved if ($this-Article-save($this-data)) { $this-Session-setFlash('Your article has been saved.'); $this-redirect('index'); } } else { // Get all tags $tags = $this-Tag-findAll(); // Make new array with tags $tagsList = array(); // Loop through array foreach ($tags as $tag) { $tagsList[$tag['Tag']['id']] = $tag['Tag']['tag']; } // Array with tags $this-set('tags', $tagsList ); // Get all menu items $menu_items = $this-Menu-findAll(); // Make new array with tags $menu_list = array(); // Loop through array foreach ($menu_items as $item) { $menu_list[$item['Menu']['id']] = $item['Menu']['name']; } // Array with tags $this-set('menu', $menu_list ); } } /** * Delete the article with id as parameter * * @param unknown_type $id */ function delete($id) { $this-Article-del($id); $this-Session-setFlash('The article with id: '.$id.' has been deleted.'); $this-redirect('index'); } /** * Edit article with id as parameter * * @param unknown_type $id */ function edit($id = null) { if (empty($this-data)) { $this-Article-id = $id; $this-data = $this-Article-read(); } else { if ($this-Article-save($this-data['Article'])) { $this-Session-setFlash('Your article has been updated.'); $this-redirect('index'); } } } } Model Article.php ?php class Article extends AppModel { // Model name var $name = 'Article'; // Database table var $useTable = 'articles'; // Use sef url's var $actsAs = array('Slug'); // Validator var $validate = array( 'title' = array('rule' = array('between', 3, 255)), 'article' = VALID_NOT_EMPTY ); var $hasAndBelongsToMany = array('Tag' = array('className'= 'Tag', 'joinTable'= 'articles_tags', 'foreignKey' = 'articles_id', 'associationForeignKey'= 'tag_id', 'conditions' = '', 'order'= '', 'limit'= '', 'unique' = true, 'finderQuery' = '', 'deleteQuery' = '', ) ); } View index.ctp: h1Articles/h1 ?php echo $html-link('New article', 'add');? table tr thId/th thTitle/th thEdit/th thDelete/th thCreated/th thModified/th /tr !-- Here's where we loop through our $posts array, printing out post info -- ?php foreach ($articles as $article): ? tr td?php echo $article['Article']['id']; ?/td td?php echo $html-link($article['Article']['title'], /
Re: Pagination in 1.2 error :(
Hi. You forgot your article model. var $uses = array('Tag', 'Menu', 'Article'); On Jun 18, 10:45 am, Mech7 [EMAIL PROTECTED] wrote: Yes offcourse here is my controller: articles_controller.php ?php /** * Article controller * All article logic is used here * * @author Chris de Kok * @version 1.0 * @package articles * */ class ArticlesController extends AppController { // Name var $name = 'Articles'; // Pagination settings var $paginate = array('limit' = 15, 'page' = 1); // Helpers var $helpers = array('Html','Form', 'Time'); // Load other models var $uses = array('Tag', 'Menu'); /** * This function shows a list of all articles * it will be called on /article or /article/index * */ function index() { $this-set('articles', $this-paginate('Article')); } /** * Function to show one article * parameter is id of the article * * @param integer $id */ function view($slug = null) { $article = $this-Article-findBySlug($slug); $this-set('article', $article); } /** * Function to save an article to the database * */ function add() { if (!empty($this-data)) { // Check if data has been saved if ($this-Article-save($this-data)) { $this-Session-setFlash('Your article has been saved.'); $this-redirect('index'); } } else { // Get all tags $tags = $this-Tag-findAll(); // Make new array with tags $tagsList = array(); // Loop through array foreach ($tags as $tag) { $tagsList[$tag['Tag']['id']] = $tag['Tag']['tag']; } // Array with tags $this-set('tags', $tagsList ); // Get all menu items $menu_items = $this-Menu-findAll(); // Make new array with tags $menu_list = array(); // Loop through array foreach ($menu_items as $item) { $menu_list[$item['Menu']['id']] = $item['Menu']['name']; } // Array with tags $this-set('menu', $menu_list ); } } /** * Delete the article with id as parameter * * @param unknown_type $id */ function delete($id) { $this-Article-del($id); $this-Session-setFlash('The article with id: '.$id.' has been deleted.'); $this-redirect('index'); } /** * Edit article with id as parameter * * @param unknown_type $id */ function edit($id = null) { if (empty($this-data)) { $this-Article-id = $id; $this-data = $this-Article-read(); } else { if ($this-Article-save($this-data['Article'])) { $this-Session-setFlash('Your article has been updated.'); $this-redirect('index'); } } } } Model Article.php ?php class Article extends AppModel { // Model name var $name = 'Article'; // Database table var $useTable = 'articles'; // Use sef url's var $actsAs = array('Slug'); // Validator var $validate = array( 'title' = array('rule' = array('between', 3, 255)), 'article' = VALID_NOT_EMPTY ); var $hasAndBelongsToMany = array('Tag' = array('className'= 'Tag', 'joinTable'= 'articles_tags', 'foreignKey' = 'articles_id', 'associationForeignKey'= 'tag_id', 'conditions' = '', 'order'= '', 'limit'= '', 'unique' = true, 'finderQuery' = '', 'deleteQuery' = '', ) ); } View index.ctp: h1Articles/h1 ?php echo $html-link('New article', 'add');? table tr thId/th thTitle/th thEdit/th thDelete/th thCreated/th
Re: Pagination in 1.2 error :(
Ah thanks now it works :D i didn't know the model of the controller itself was required also if you add other models :) On 18 jun, 19:04, rtconner [EMAIL PROTECTED] wrote: Hi. You forgot your article model. var $uses = array('Tag', 'Menu', 'Article'); On Jun 18, 10:45 am, Mech7 [EMAIL PROTECTED] wrote: Yes offcourse here is my controller: articles_controller.php ?php /** * Article controller * All article logic is used here * * @author Chris de Kok * @version 1.0 * @package articles * */ class ArticlesController extends AppController { // Name var $name = 'Articles'; // Pagination settings var $paginate = array('limit' = 15, 'page' = 1); // Helpers var $helpers = array('Html','Form', 'Time'); // Load other models var $uses = array('Tag', 'Menu'); /** * This function shows a list of all articles * it will be called on /article or /article/index * */ function index() { $this-set('articles', $this-paginate('Article')); } /** * Function to show one article * parameter is id of the article * * @param integer $id */ function view($slug = null) { $article = $this-Article-findBySlug($slug); $this-set('article', $article); } /** * Function to save an article to the database * */ function add() { if (!empty($this-data)) { // Check if data has been saved if ($this-Article-save($this-data)) { $this-Session-setFlash('Your article has been saved.'); $this-redirect('index'); } } else { // Get all tags $tags = $this-Tag-findAll(); // Make new array with tags $tagsList = array(); // Loop through array foreach ($tags as $tag) { $tagsList[$tag['Tag']['id']] = $tag['Tag']['tag']; } // Array with tags $this-set('tags', $tagsList ); // Get all menu items $menu_items = $this-Menu-findAll(); // Make new array with tags $menu_list = array(); // Loop through array foreach ($menu_items as $item) { $menu_list[$item['Menu']['id']] = $item['Menu']['name']; } // Array with tags $this-set('menu', $menu_list ); } } /** * Delete the article with id as parameter * * @param unknown_type $id */ function delete($id) { $this-Article-del($id); $this-Session-setFlash('The article with id: '.$id.' has been deleted.'); $this-redirect('index'); } /** * Edit article with id as parameter * * @param unknown_type $id */ function edit($id = null) { if (empty($this-data)) { $this-Article-id = $id; $this-data = $this-Article-read(); } else { if ($this-Article-save($this-data['Article'])) { $this-Session-setFlash('Your article has been updated.'); $this-redirect('index'); } } } } Model Article.php ?php class Article extends AppModel { // Model name var $name = 'Article'; // Database table var $useTable = 'articles'; // Use sef url's var $actsAs = array('Slug'); // Validator var $validate = array( 'title' = array('rule' = array('between', 3, 255)), 'article' = VALID_NOT_EMPTY ); var $hasAndBelongsToMany = array('Tag' = array('className'= 'Tag', 'joinTable'= 'articles_tags', 'foreignKey' = 'articles_id', 'associationForeignKey'= 'tag_id', 'conditions' = '', 'order'= '', 'limit'= '',
Re: Pagination in 1.2 error :(
lol, the cake way: long questions, short answers On Jun 18, 11:09 am, Mech7 [EMAIL PROTECTED] wrote: Ah thanks now it works :D i didn't know the model of the controller itself was required also if you add other models :) On 18 jun, 19:04, rtconner [EMAIL PROTECTED] wrote: Hi. You forgot your article model. var $uses = array('Tag', 'Menu', 'Article'); On Jun 18, 10:45 am, Mech7 [EMAIL PROTECTED] wrote: Yes offcourse here is my controller: articles_controller.php ?php /** * Article controller * All article logic is used here * * @author Chris de Kok * @version 1.0 * @package articles * */ class ArticlesController extends AppController { // Name var $name = 'Articles'; // Pagination settings var $paginate = array('limit' = 15, 'page' = 1); // Helpers var $helpers = array('Html','Form', 'Time'); // Load other models var $uses = array('Tag', 'Menu'); /** * This function shows a list of all articles * it will be called on /article or /article/index * */ function index() { $this-set('articles', $this-paginate('Article')); } /** * Function to show one article * parameter is id of the article * * @param integer $id */ function view($slug = null) { $article = $this-Article-findBySlug($slug); $this-set('article', $article); } /** * Function to save an article to the database * */ function add() { if (!empty($this-data)) { // Check if data has been saved if ($this-Article-save($this-data)) { $this-Session-setFlash('Your article has been saved.'); $this-redirect('index'); } } else { // Get all tags $tags = $this-Tag-findAll(); // Make new array with tags $tagsList = array(); // Loop through array foreach ($tags as $tag) { $tagsList[$tag['Tag']['id']] = $tag['Tag']['tag']; } // Array with tags $this-set('tags', $tagsList ); // Get all menu items $menu_items = $this-Menu-findAll(); // Make new array with tags $menu_list = array(); // Loop through array foreach ($menu_items as $item) { $menu_list[$item['Menu']['id']] = $item['Menu']['name']; } // Array with tags $this-set('menu', $menu_list ); } } /** * Delete the article with id as parameter * * @param unknown_type $id */ function delete($id) { $this-Article-del($id); $this-Session-setFlash('The article with id: '.$id.' has been deleted.'); $this-redirect('index'); } /** * Edit article with id as parameter * * @param unknown_type $id */ function edit($id = null) { if (empty($this-data)) { $this-Article-id = $id; $this-data = $this-Article-read(); } else { if ($this-Article-save($this-data['Article'])) { $this-Session-setFlash('Your article has been updated.'); $this-redirect('index'); } } } } Model Article.php ?php class Article extends AppModel { // Model name var $name = 'Article'; // Database table var $useTable = 'articles'; // Use sef url's var $actsAs = array('Slug'); // Validator var $validate = array( 'title' = array('rule' = array('between', 3, 255)), 'article' = VALID_NOT_EMPTY ); var $hasAndBelongsToMany = array('Tag' = array('className'=
Pagination in 1.2 error :(
http://bakery.cakephp.org/articles/view/basic-pagination-overview-3#comment-1004 I have used this little walkthrough and it works fine.. but when i add another model to the controller like.. var $uses = array('Tag', 'Menu'); Then it throws and error: Notice (8): Undefined variable: paginator [CORE\app\views\articles \index.ctp, line 36] Fatal error: Call to a member function prev() on a non-object in C: \wamp\www\mech7\app\views\articles\index.ctp on line 36 Anybody know how to fix this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Pagination in 1.2 error :(
Also saving now does not seem to work anymore? Notice (8): Undefined property: ArticlesController::$Article [CORE\app \controllers\articles_controller.php, line 59] if (!empty($this-data)) { // Check if data has been saved if ($this-Article-save($this-data)) { $this-Session-setFlash('Your article has been saved.'); ArticlesController::add() - CORE\app\controllers \articles_controller.php, line 59 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 341 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 323 [main] - CORE\app\webroot\index.php, line 83 Fatal error: Call to a member function save() on a non-object in C: \wamp\www\mech7\app\controllers\articles_controller.php on line 59 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---