Your problem is that you're not using pagination. You have to use
$this->paginate() instead of find(). The way you've set up your
conditions is a bit strange to me, also.
class PostsController extends AppController
{
public $paginate = array(
'Post' => array(
'conditions' => array(
'Post.active' => 1
),
'fields' => array('posts.*'),
'limit' => YOUR_LIMIT_HERE,
'order' => array('Posts.id' => 'DESC'),
'recursive' => 1
)
);
public function your_action()
{
if ($this->data['post']['comp'] !='')
{
$this->paginate['Post']['conditions'][] = "Post.body
LIKE
'%{$this->data['post']['comp']}%'";
}
if ($this->data['post']['phone'] !='')
{
$this->paginate['Post']['conditions'][] = "Post.phone
LIKE
'{$this->data['post']['phone']}'";
}
$this->set('results', $this->paginate('Post'));
}
Note that I changed posts.active to Post.phone. I'm guessingthat was a mistake.
Also, shouldn't it be 'Post.phone' => $this->data['post']['phone'] ?
On Sat, Jul 18, 2009 at 1:03 PM, bino dev<[email protected]> wrote:
> Hi Friends,
>
> Iam very new in cake php.
> I need a help on the pagination . Actually iam trying to make a search with
> the company and phone number. Iam pasting the code below. When i search with
> a company with 'A' iam getting the result which have the compnay name which
> starts with A. When i go to the next page the all results are showing (
> because query is changing due to compnay values is null). How can i solve it
> .
>
> ---------------------------------
> my controller code
>
> if
>
> ($this->data['post']['comp'] !='') {
>
> $datass .=" and posts.body like '%". $this->data['post']['comp']."%'";
>
> }
>
> if($this->data['post']['phone'] !='') {
>
> $datass .=" and posts.active like '". $this->data['post']['phone']."'";
>
> }
>
> $criteria='post.active =1';
>
> list($order,$limit,$page) = $this->Pagination->init($criteria);
>
> $sql = array('conditions' => array($datass),
>
> 'recursive' => 1 ,
>
> 'fields' => array('posts.*'),
>
> 'order' => array( 'posts.id DESC'),
>
> 'limit' => $limit,
>
> 'page' => $page
>
> );
>
> $tasks = $this->posts->find('all',$sql );
>
> $this->set('results', $tasks);
>
> ----------------------
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---