Hey puatki,
First thing I ever do when trying out the new functions is have a look
at the core code. The paginate function doesn't accept the same
arguments as the findAll. There is no way to define fields directly in
that function.
What you have to do instead is use the `paginate` attribute of your
controller. Now, apparently you can define conditions on a per model
basis, but I haven't figure that out just yet. I have successfully
created a count field and passed it to paginate via the following
method.
Within your action, in your controller, prior to calling paginate add
the following :
$this->paginate['fields'] = array('id','username','code','SUM(cash) as
suma', 'COUNT(User.id) AS click');
You also have to define your order in this way. So for you it would be :
$this->paginate['order'] = $order;
Similarly for limit and page. Although, I usually define these in my
app_controller in the attribute definitions up the top (near the
components and helpers and stuff) :
// pagination
var $paginate = array('limit' => 5, 'page' => 1);
Now, when you call the paginate method you only need to pass it the
conditions. The function definition is as follows :
function paginate($object = null, $scope = array(), $whitelist = array()) {
if (is_array($object)) {
$whitelist = $scope;
$scope = $object;
$object = null;
}
...
}
Note the first snippet of code that allows you to pass a model just in
case the model you will be paginating is not the modelClass of the
controller your in.
Hope this helps.
Cheers,
freedom
On 07/11/2007, puatki <[EMAIL PROTECTED]> wrote:
>
> Thanks for answer ;)
>
> I have cake 1.2. I know how to paginate something "simple". Here I
> have some count() and sum() fields, group by etc and I do not know how
> to do this with paginate.
> $this->paginate( $conditions ) did not work for me.
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---