Re: Display both featured AND last posts.

2012-01-02 Thread Linas Jakucionis
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.  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  it doesn't work...
>
>
>
> On 2 jan, 17:17, euromark  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."  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 :
>>
>> >  
>>
>> > 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 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
> cake-php+unsubscr...@googlegroups.com 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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: How to write unit test for getPopularItems()?

2011-11-21 Thread Linas Jakucionis
Hi,

Common practice is to write unit tests against known test data, rather than
against unknown production data.

That way you could compare the actual values returned.

When doing testing against unknown data you are limited to whatever extra
checks you can make:
* is the correct number of items returned
* do all of them contain count greater than 0
* are they all sorted in (alphabetical | count) order

Linas

On Sun, Nov 20, 2011 at 3:31 AM, Todong  wrote:

> Hi,all
>
> The Item can be viewed by visitor, the viewed counter will be saved in
> database table(e.g. Items table). So getPopularItems() is to get the
> most viewed items, according to the viewed counter of items.
>
> The problem is:
> What should I check in test case for getPopularItems()?
>
> Since getPopularItems() get most viewed items according to the viewed
> counter, If I use this method again to get most viewed items in
> testGetPopularItems() and check if these two collections(popular
> items) are equal, isn't it duplication?
>
> I thought up one method:
> Get the viewed count of most viewed(the first) item, then compare it
> to the viewed count of several random items, check whether the former
> viewed count is bigger or equal than latter one.
>
> Is this method OK?
>
> Any suggestion is appreciated.
>
> --
> 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
> cake-php+unsubscr...@googlegroups.com 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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php