Can I get the number of rows in a CRUD

81 views
Skip to first unread message

The Black Pig

unread,
Nov 16, 2012, 7:51:33 AM11/16/12
to agile-too...@googlegroups.com
I have multiple CRUDs being displayed on a page.

is it possible to get the number of rows in a CRUD.

e.g.

$c = $p->add('CRUD');
$c
->setModel('MyModel');
$cnt
= $c->count;


$c
= $p->add('CRUD');
$c
->setModel('MyOtherModel');
$cnt
+= $c->count;

BP

Imants Horsts

unread,
Nov 16, 2012, 9:31:16 AM11/16/12
to agile-too...@googlegroups.com
1. Number of rows will be not in CRUD, but in Grid which is part of CRUD. Don't mix these terms please or you can get in trouble with debugging your code. It was the same with me at the beginning :)

2. I have no ready full solution for this, but you have to look into: /lib/DB/dsql/mysql.php method named calc_found_rows() and somehow use SQL_CALC_FOUND_ROWS option to do this.
Something similar is done in Paginator class, setSource method. Check that out!

You have to do something like this (not tested, just pseudo code to give you idea):
$c = $p->add('CRUD');

$m
= $p->add('MyModel');
$m
->debug(); // add debug info
$m
= $m->_preexec(); // start iterating early
$m
->calc_found_rows(); // add SQL_CALC_FOUND_ROWS option
$m
= $c->setModel($m); // add model to CRUD
$cnt
= count($m);
Probably you should also add check if ($c->grid) { ... only then try to count rows, otherwise it's useless ... }

Imants Horsts

unread,
Nov 16, 2012, 9:32:13 AM11/16/12
to agile-too...@googlegroups.com
Typo: $m = $c->setModel($m); should be simply $c->setModel($m);


On Friday, November 16, 2012 2:51:33 PM UTC+2, The Black Pig wrote:

Romans Malinovskis

unread,
Nov 16, 2012, 10:54:38 AM11/16/12
to agile-too...@googlegroups.com
This should still work OK 

--
 
 

--
I am working with my team on a VERY URGENT project now. I apologize for the delay in answering your email(s).

Romans Malinovskis is the author of the revolutionary PHP Framework: the “Agile Toolkit” (www.agiletoolkit.org). Please show your support by raising awareness about Agile Toolkit.

Refer commercial web development projects towards our skilled developer team: http://www.agiletech.ie/company/




Romans Malinovskis

unread,
Nov 16, 2012, 10:56:54 AM11/16/12
to agile-too...@googlegroups.com
Check this out:

 class MyGrid extends CompleteLister {
     function render(){
         $this->model->_dsql()->calc_found_rows();
         parent::render();
         $this->owner->template->trySet(‘rows',$this->model->_dsql()->>
     }
}

then you just need to have a template value.  The great thing about this - you don’t need extra select. If you do want extra select, you could do

$m->count()->getOne();

romans

--
 
 

The Black Pig

unread,
Nov 16, 2012, 11:34:32 AM11/16/12
to agile-too...@googlegroups.com
Hi Romans,

That looks pretty cool but it's just for displaying the number of rows in the template?

I actually need the value so that I can perform other calculations based on it.

I think Imants solution will work best for me at the moment.
Reply all
Reply to author
Forward
0 new messages