RE: create a link with conditions to filter index action

2010-01-14 Thread Ben Gallienne
Thanks, Jon, that's perfect.

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of 
Jon Bennett
Sent: 14 January 2010 15:07
To: cake-php@googlegroups.com
Subject: Re: create a link with conditions to filter index action

hi Ben,

Used named parameters:

$html->link($category_name, array(
'controller'=>'Blogs',
'action'=>'index',
'category_id'=>3,
'tag_id'=>4
));

public function index()
{
extract($this->params['named']);

$conditions = array();

if (isset($category_id))
$conditions['Blog']['category_id'] = $category_id;

if (isset($tag_id))
$conditions['Blog']['tag_id'] = $tag_id;

// etc
}

hth

Jon


-- 
jon bennett - www.jben.net - blog.jben.net

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: create a link with conditions to filter index action

2010-01-14 Thread Jon Bennett
hi Ben,

Used named parameters:

$html->link($category_name, array(
'controller'=>'Blogs',
'action'=>'index',
'category_id'=>3,
'tag_id'=>4
));

public function index()
{
extract($this->params['named']);

$conditions = array();

if (isset($category_id))
$conditions['Blog']['category_id'] = $category_id;

if (isset($tag_id))
$conditions['Blog']['tag_id'] = $tag_id;

// etc
}

hth

Jon


-- 
jon bennett - www.jben.net - blog.jben.net
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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


RE: create a link with conditions to filter index action

2010-01-14 Thread Ben Gallienne
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: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of Jeremy Burns
Sent: 14 January 2010 14:20
To: cake-php@googlegroups.com
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
jeremybu...@me.com
(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 cake-php@googlegroups.com To 
> unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: create a link with conditions to filter index action

2010-01-14 Thread Jeremy Burns
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
jeremybu...@me.com
(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 cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en