Home

April 24th, 2008

12:30 am

OK, so I've been hunting all evening for something that's been in front of my face the entire time.
All I wanted to do was paginate() the result of a specific query... THAT'S MY PROBLEM. I was asking the wrong question. I wanted to paginate the result of a particular condition.
I went as far as creating the specific paginate query in the model (which is where complex paginate queries go, not the controller). Then I asked myself, if I can pass it a $condition, why can't I just do that in the controller with the default paginate().
THEN IT HIT ME! $this->paginate is a fancy kind of Model::findAll(). The same options you can give findAll() you can give to paginate().
OK, so...
  1. You can set some defaults to $this->paginate() as a 'var' in the controller called 'paginate'. (See previous post) This will apply to all vanilla $this->paginate() calls.
  2. $this->paginate() returns what $this->Post->findAll() would return.
    1. It also accepts all options findAll() would accept.
    2. Use it as you would findAll(): http://book.cakephp.org/view/448/findall
Putting it all together, five hours ago, in my "non index action" all I needed to do was:

$conditions = array('Journal.incident_id' => $incidentId);

// $journals = $this->Journal->findAll($conditions);
$journals = $this->paginate($conditions);
$this->set('journals', $journals);
You know, for all the time CakePHP is 'saving' me by auto-generating this code, it's taking back by lack of cohesive well written documentation. Does that mean I give up... ugh, dzang, no... when I 'get' it and it works... it REALLY WORKS! :)

I just wish I had more time. I have to get this site done by May 15.

11:35 am
Joe Coffee Bar on PBS's NOW

Joe Coffee is on PBS's NOW (with David Broncaccio) http://www.pbs.org/now/shows/416/index.html
You can watch it in its entirety online. There's even a cameo of me! Well not really a cameo if you call a blob in the background one.
Health care costs in the Keystone State are 11 percent higher than the national average and rising twice as fast as the average wage. The state legislature is debating a plan backed by Governor Ed Rendell to provide benefits to hundreds of thousands of Pennsylvanians, but there's disagreement over who's going to foot the bill.