You should create a Category model and set that up as a tree so as to
have subcategories. Category hasMany Article; Article belongsTo
Category.
When you create your links, point to an action in
CategoriesController, which in turn calls a function in Category
model:
public function articles($id = null)
{
return $this->find(
'all',
array(
'conditions' => array(
$this->alias.'.id' => $id
),
'contain' => array('Article')
)
);
}
This grabs the chosen Category and all related Articles.
Better yet, use SluggableBehavior and pass the slug instead of the id
so as to have nicer URLs.
On Sun, Dec 9, 2012 at 6:31 PM, Salines <nikola.paradzik@gmail.com> wrote:
> Hello,
>
> Let me explain my problem
>
> table 'posts' was organized as a tree, where the parents are a different
> topic content. While the last child in the branches of the tree is always an
> article.
> As you can guess the path between the root and the last child is at
> different depths depending on how the content is organized.
>
> Here are a few examples.
>
> Sports -> Basketball -> Men -> Articles
> Sports -> Basketball -> Women -> Articles
> Sports -> Basketball -> Team -> Premier League -> Articles
> Sports -> Basketball -> Team -> second division -> Articles
> Sports -> Recreation -> Articles
>
>
> What should I do when I click on eg sport that listing of the latest
> articles from all its child categories
> Also important to note is required for pagination and content as listed.
>
> I'm not sure what to use TreeBehavior children::method that returns all the
> items,( for example, to make a custom pagination)
> http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::children
>
> or find ('threaded') which also returns the correct results???
>
> My brain is frozen, just like the icy weather outside :)
>
> Thank you for your advice.
> Nikola
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com.
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
Sunday, December 9, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment