Re: Pagination in 1.2 error :(

2007-06-18 Thread rtconner

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
>
> > >  > > /**
> > >  * 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
>
> > >  > > class Article extends AppModel
> > > {
> > > // M

Re: Pagination in 1.2 error :(

2007-06-18 Thread Mech7

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
>
> >  > /**
> >  * 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
>
> >  > 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
> >

Re: Pagination in 1.2 error :(

2007-06-18 Thread rtconner

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
>
>  /**
>  * 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
>
>  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'  => '',
> )
> );
>
>

Re: Pagination in 1.2 error :(

2007-06-18 Thread Mech7

Yes offcourse here is my controller:

articles_controller.php

 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

 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:

Articles
link('New article', 'add');?>


Id
Title
Edit
Delete
Created
Modified


   




link($article['Article']['title'], "/
articles/view/".$article['Article']['slug']); ?>
link(
'Edit',
"/articles/edit/{$article['Article']['id']}")?>

link(
'Delete',
"/articles/delete/{$article['Article']['id']}",
null,
'Are you sure?'
)?>

timeAgoInWords(strtotime($article['Article']['created'])); ?>
timeAgoInWords(strtotime($article['Article']['modified'])); ?>




prev(); ?>
numbers(); ?>
next(); ?>

And the tables:

CREATE TABLE `cms_articles` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) character set utf8 NOT NULL,
  `slug` varchar(100) character set utf8 NOT NULL,
  `article` text character set utf8 NOT NULL,
  `menu_id` int(11) NOT 

Re: Pagination in 1.2 error :(

2007-06-18 Thread Titang

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 :(

2007-06-17 Thread Mech7

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
-~--~~~~--~~--~--~---



Pagination in 1.2 error :(

2007-06-17 Thread Mech7

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
-~--~~~~--~~--~--~---