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' => 'Tag',
> > > 'joinTable' => 'articles_tags',
> > > 'foreignKey' => 'articles_id',
> > > 'associationForeignKey'=> 'tag_id',
> > > 'conditions' => '',
> > > 'order' => '',
> > > 'limit' => '',
> > > 'unique' => true,
> > > 'finderQuery' => '',
> > > 'deleteQuery' => '',
> > > )
> > > );
>
> > > }
>
> > > View
>
> > > index.ctp:
>
> > > <h1>Articles</h1>
> > > <?php echo $html->link('New article', 'add');?>
> > > <table>
> > > <tr>
> > > <th>Id</th>
> > > <th>Title</th>
> > > <th>Edit</th>
> > > <th>Delete</th>
> > > <th>Created</th>
> > > <th>Modified</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'], "/
> > > articles/view/".$article['Article']['slug']); ?></td>
> > > <td><?php echo $html->link(
> > > 'Edit',
> > > "/articles/edit/{$article['Article']['id']}")?>
> > > </td>
> > > <td><?php echo $html->link(
> > > 'Delete',
> > > "/articles/delete/{$article['Article']['id']}",
> > > null,
> > > 'Are you sure?'
> > > )?>
> > > </td>
> > > <td><?php echo
> > > $time->timeAgoInWords(strtotime($article['Article']['created'])); ?></td>
>
> > > <td><?php echo
> > > $time->timeAgoInWords(strtotime($article['Article']['modified'])); ?></td>
>
> > > </tr>
> > > <?php endforeach; ?>
>
> > > </table>
> > > <?php echo $paginator->prev(); ?>
> > > <?php echo $paginator->numbers(); ?>
> > > <?php echo $paginator->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 NULL,
> > > `created` datetime NOT NULL,
> > > `modified` datetime NOT NULL,
> > > PRIMARY KEY (`id`)
> > > ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
> > > CREATE TABLE `cms_tags` (
> > > `id` int(11) NOT NULL auto_increment,
> > > `tag` varchar(255) NOT NULL,
> > > PRIMARY KEY (`id`)
> > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
>
> > > CREATE TABLE `cms_articles_tags` (
> > > `articles_id` int(11) NOT NULL,
> > > `tag_id` int(11) NOT NULL,
> > > PRIMARY KEY (`articles_id`,`tag_id`)
> > > ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
> > > CREATE TABLE `cms_menu` (
> > > `id` int(11) NOT NULL,
> > > `name` varchar(255) NOT NULL,
> > > `parent_id` int(11) NOT NULL,
> > > PRIMARY KEY (`id`)
> > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
>
> > > CREATE TABLE `cms_menu` (
> > > `id` int(11) NOT NULL,
> > > `name` varchar(255) NOT NULL,
> > > `parent_id` int(11) NOT NULL,
> > > PRIMARY KEY (`id`)
> > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
>
> > > On 18 jun, 10:15, Titang <[EMAIL PROTECTED]> wrote:
>
> > > > 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---