Would a more experienced programmer please explain how I can move a Finder method from a controller to its associated model? I've seen examples of this in Rails, but not in akelos/PHP. My inexperience with OOP in PHP has me stumped. Offering a simple example of the resulting code in both the controller and model would be great. Thank you.
CommentAuthorpweil
I found at least part of the answer on my own. Perhaps this will be helpful to other akelos newbies. Given controller "resource_controller.php" and mode 'resource.php', a simple Finder method can be placed in the model:
function myFind() { return $this->find('all'); }
This can be called from a method in the controller:
function callmyFind { $this->resources = $this->Resource->myFind(); }
This raises another question: how would one call the pagination helper in this situation? I've tried a number of variations, but I keep getting errors citing an undefined property or call to a member function on a non-object. Surely someone out there understands what kinds of syntax changes are needed to do this from within the model rather than the controller? thanks in advance.
CommentAuthorpweil
Ok, I think I solved this one too. Maybe there's a better way to do this, but I ended up passing the paginator_helper options to the model as a parameter:
In the controller: (pass the pagination options [a variable] as a parameter)
function gomodelFind() { $this->resource_pages = $this->pagination_helper->getPaginator($this->Resource, array('items_per_page' => 20));
I hope this helps someone so they don't have to spend time figuring it out.
CommentAuthorpweil
Well, I spoke too soon. The pagination options don't come through, although no error is thrown. It keeps showing all of the records, even though it offers multiple pages. Anyone?