Great!
That worked out after some cofiguring and thinking. Here is the result, I hope
this example helps someone someday:
In the controller:
function getHotelmastertexte($hotelmaster_id = null) {
if (!empty($this->data)) {
//additional searchparameters from the form
$param = array('Textmaster.katalogobjekt_id' => 1,
'Textmaster.sprache_id' => 1,
'Textmaster.textinhalt LIKE' =>
'%'.trim($this->data['Textmaster']['textinhalt']).'%',
'Textmaster.suchkriterium LIKE' =>
'%'.trim($this->data['Textmaster']['suchkriterium']).'%');
$data = $this->data['Textmaster'];
} else
{
//no additional searchparametes beside our default
conditions
$param = array('Textmaster.katalogobjekt_id' => 1,
'Textmaster.sprache_id' => 1);
$data = array('textinhalt' => '', 'suchkriterium' =>
'', 'id' => '');
}
// pagination ole!
$paginator_params = array();
$paginator_params['controller'] = 'textmasters';
$paginator_params['action'] = $this->action.'/'.$hotelmaster_id;
$this->paginate['Textmaster'] = array(
'limit' => 10,
'order' => array ('Textmaster.suchkriterium' => 'asc'),
'url' => $paginator_params
);
//here we fetch the data
$textmasters = $this->paginate('Textmaster',$param);
$hmid = $hotelmaster_id;
$this->set('hmid',$hmid);
$this->set(compact('textmasters', 'paginator_params','data'));
}
In the view:
<?php
$paginator->options(array('url' =>
isset($this->params['pass'])?$this->params['pass']:array()));
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of
%count% total, starting on record %start%, ending on %end%', true)
));
?>
And at the bottom:
<div class="paging">
<?php echo $paginator->prev('<< Previous', (isset($paginator_params)?
$paginator_params : null), null, array('class' => 'disabled'));
?> <?php echo $paginator->numbers((isset($paginator_params) ?
$paginator_params : null));
?> <?php echo $paginator->next('Next >>', (isset($paginator_params) ?
$paginator_params : null), null, array('class' => 'disabled')); ?>
<br>page <?php echo $paginator->counter(array('separator' => ' of
'));?>
</div>
Pagination with numbers and passing on URL-parameters. That ist not a simple
cake that is already a death-by-chocolate cake!
Anja
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[EMAIL PROTECTED] Im Auftrag von
RichardAtHome
Gesendet: Dienstag, 9. September 2008 10:46
An: CakePHP
Betreff: Re: Find: conditions and fields
What David said.
You have to add your conditions to the paginate call.
Check out the google groups FAQ: http://groups.google.com/group/cake-php/web/faq
Scroll down to: How to add paginate support for custom queries?
On Sep 9, 9:13 am, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
> See:http://groups.google.com/group/cake-php/msg/7d17a42d764ccce4?hl=en
>
> Your problem is not in your conditions, it's right here:
>
> > $this->set('textmasters', $this->paginate());
>
> Yes, this in fact does give you *everything*.
>
> On 9 Sep 2008, at 17:04, Liebermann, Anja Carolin wrote:
>
>
>
> > Hello,
>
> > I still have some problems with the parameters for "find"
>
> > I have two different sets of parameters but I have the impression
> > the result doesn't react on them, but simply gives me a list with
> > nearly all of my datasets:
>
> > Version 1:
> > $params = array(
> > 'conditions' => array('Textmaster.katalogobjekt_id' => 1,
> > 'Textmaster.sprache_id' => 1,
> > 'Textmaster.textinhalt LIKE' =>
> > '%'.trim($this->data['Textmaster']['textinhalt']).'%',
> > 'Textmaster.suchkriterium LIKE' =>
> > '%'.trim($this->data['Textmaster']['suchkriterium']).'%'),
> > 'fields' =>
> > array
> > ('Textmaster.id','Textmaster.suchkriterium','Textmaster.textinhalt'
> > ),
> > 'order' => 'Textmaster.suchkriterium ASC', 'recursive' => -1 );
>
> > Version 2:
> > $params = array(
> > 'conditions' => array('Textmaster.katalogobjekt_id' => 1,
> > 'Textmaster.sprache_id' => 1), 'fields' => array
> > ('Textmaster.id','Textmaster.suchkriterium','Textmaster.textinhalt'
> > ),
> > 'order' => 'suchkriterium ASC',
> > 'recursive' => -1
> > );
>
> > $textmasters = $this->Textmaster->find('all',$params);
> > $this->set('textmasters', $this->paginate());
>
> > Question 1: What does 'fields' do? I thought it would load only
> > those fields, but my dataset seems to load completely because in the
> > view every column is populated
>
> > Question 2: the 'order' criteria is being ignored. Do I have the
> > wrong syntax? The result is still sorted by 'id'.
>
> > Question 3: the "like" condition is also ignored, although it
> > arraives in the parameter array:
> > E.g.:
> > Array
> > (
> > [conditions] => Array
> > (
> > [Textmaster.katalogobjekt_id] => 1
> > [Textmaster.sprache_id] => 1
> > [Textmaster.textinhalt LIKE] => %Modern%
> > [Textmaster.suchkriterium LIKE] => %ACE109%
> > )
>
> > [fields] => Array
> > (
> > [0] => Textmaster.id
> > [1] => Textmaster.suchkriterium
> > [2] => Textmaster.textinhalt
> > )
>
> > [order] => Textmaster.suchkriterium ASC
> > [recursive] => -1
> > )
>
> > Any hints on what is going wrong are appreciated.
>
> > Anja C. Liebermann
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---