Hey Helmi,
Couldn't you change your index action of your Categories controller to
accept a slug instead of an id?
i.e. from an url like
/category/testcat
in your CategoriesController, modify your index action to receive a
slug as it's sole parameter.
function index ($slug = null)
{
}
Then, query your Category model by slug
e.g.
$category = $this->Category>findBySlug($slug);
Then you can find your jokes by category id as follows :
$conditions = array(
'Joke.category_id' => $category[Category]
);
$jokes = $this->Category->Joke->findAll($conditions);
$this->set('jokes',$jokes);
Would that work?
You could do something similar, but in reverse, from your Jokes
controller. But your url would be more like :
/jokes/testcat
HTH,
mikee
On 17/02/07, Helmi <[EMAIL PROTECTED]> wrote:
>
> Hi list,
>
> i'm new to cakePHP so sorry if this has been answered 100 times before
> but i couldn't find something like this.
>
> I'm currently developing my first little test project with cakes which
> is a simple joke-directory. I have two models: Joke and Category. To
> the categories table i added a slug which should be used to represent
> the category name in the url.
>
> example: A category named "this is a test category" could have the
> slug "testcat" and the url /category/testcat
>
> i created a method "list_by_cat" to list all jokes by category which
> works great giving the category-id within the url:
>
> function list_by_cat($id=null)
> {
> $this->set('jokes', $this->Joke->findAll('category_id = '.
> $id));
> }
>
> now i want to go into the next step and use the slug instead of the
> id. Unfortunately i don't have a clue how cake can handle this cross-
> query smart ;) jokes table has the category_id and the categories
> table has the slug field which has to be queried to find the id of the
> category.
>
> Any help or documentation link is highly appreciated ;)
>
> Thanks,
> Frank
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---