There's no point in doing two identical finds - it's inefficient. If you really
want two variables with exactly the same content, do this:
$posts = $this->Post->find('all', array('conditions' => array('Post.featured'
=> '1'),'limit' => 10)));
$this->set('posts', $posts);
$this->set('posts2', $posts);
I'm still a little confused about what you are trying to achieve.
Jeremy Burns
Class Outfit
http://www.classoutfit.com
On 2 Jan 2012, at 17:53:29, J. wrote:
> Didn't knew this. Thanks a lot, works perfectly !
>
> On 2 jan, 18:36, Linas Jakucionis <[email protected]> wrote:
>> Hi,
>>
>> $this->set specifies the variable name that is supposed to be used in
>> the template, so your code snippet should look like this:
>>
>> $this->set('posts', $this->Post->find('all', array('conditions' =>
>> array('Post.featured' => '1'),'limit' => 10)));
>> $this->set('posts2', $this->Post->find('all',array('conditions' =>
>> array('Post.featured' => '1'),'limit' => 10)));
>>
>> Linas
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Jan 2, 2012 at 11:38 AM, J. <[email protected]> wrote:
>>> But I can't habe both of them named $posts, right ?
>>
>>> this->loadModel('Post');
>>> $posts = $this->set('posts', $this->Post->find('all',
>>> array('conditions' => array('Post.featured' => '1'),'limit' => 10)));
>>> $posts2 = $this->set('posts', $this->Post-
>>>> find('all',
>>> array('conditions' => array('Post.featured' => '1'),'limit' => 10)));
>>
>>> And if I do a <?php foreach ($posts2 as $post): ?> it doesn't work...
>>
>>> On 2 jan, 17:17, euromark <[email protected]> wrote:
>>>> create a second query, pass the result on to the view and loop over it
>>>> absolutely no different from your above code.
>>
>>>> On 2 Jan., 16:00, "J." <[email protected]> wrote:
>>
>>>>> I want to display both feat. and last posts on my home page.
>>
>>>>> So, in my Pages controller, I have this :
>>
>>>>> $this->loadModel('Post');
>>>>> $posts = $this->set('posts', $this->Post->find('all',
>>>>> array('conditions' => array('Post.featured' => '1'),'limit' => 10)));
>>
>>>>> and in my view I use :
>>
>>>>> <?php foreach ($posts as $post): ?>
>>
>>>>> How can I display latest posts in an other foreach too since I already
>>>>> defined it in the controller ?
>>
>>>>> Thanks for your time !
>>
>>> --
>>> Our newest site for the community: CakePHP Video
>>> Tutorialshttp://tv.cakephp.org
>>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
>>> others with their CakePHP related questions.
>>
>>> To unsubscribe from this group, send email to
>>> [email protected] For more options, visit this group
>>> athttp://groups.google.com/group/cake-php
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php