That's great, thanks for your help! I guess if I wanted the option of
additional parameters I could do something like:

$html->link($category_name,array('controller'=>'Blogs',
'action'=>'index', null, 5));

function index($category_id = null, $tag_id = null)

Does that look right?

Also, do you know if this will work with pagination and habtm relationships?
After some googling this morning around my problem, I came across this a few
times as a kind of known issue, so wondered if perhaps it was related? My
categories and tags are in habtm reference tables.

Thanks again for the advice.


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Jeremy Burns
Sent: 14 January 2010 14:20
To: [email protected]
Subject: Re: create a link with conditions to filter index action

If you are only ever going to filter for category_id, you could do this:
> $html->link($category_name,array('controller'=>'Blogs',
> 'action'=>'index', 3));

Then change you index function to:

function index($category_id = null)

...and then check for a non null value later in your code when you do your
data extraction.

Jeremy Burns
[email protected]
(Skype) +44 208 123 3822 (jeremy_burns)
(m) +44 7973 481949
(h) +44 208 530 7573

On 14 Jan 2010, at 10:47, nyahoo wrote:

> Hi All,
> 
> I hope someone can help me with what I think is a simple question that 
> I just haven't wrapped my head round yet. (I'm new to CakePHP).
> 
> I want to create a link that requests the index action of my blog 
> (which is paginated), but at the same time passes it a condition, like
> category_id=2 or something like that, so that I can have a list of 
> categories to the right of my blog index that reloads the page with 
> just that categories blogs. This seems like a straightforward idea to 
> me, but I don't seem to be able to get the syntax right. I can do 
> limits and orders but not conditions. Can anyone help me please?
> 
> Some examples:
> 
> This works:
> $html->link($category_name,array('controller'=>'Blogs',
> 'action'=>'index', 'limit'=>2));
> 
> This doesn't work:
> $html->link($category_name,array('controller'=>'Blogs',
> 'action'=>'index', 'conditions'=>'Blog.category_id=3'));
> 
> My controller code:
> function index() {
>       $this->Blog->recursive = 0;
>       $this->set('blogs', $this->paginate()); }
> 
> Thanks for any advice in advance!
> Check out the new CakePHP Questions site http://cakeqs.org and help others
with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups
"CakePHP" 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 
> cake-php+group at http://groups.google.com/group/cake-php?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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

Reply via email to