CakePHP Helper – the fetcher, what we all need, as simple as it is

Sometimes you encounter a place where in a view you need to intiate a model and fetch some information, requestAction is not recommened and currently CakePHP provide a simple way to fetch a model data.

so how can it be done, easily we had made the Fetcher helper that can help you get link, news, users whatever you need from your module writing a few lines of code:

<?php

class FetcherHelper extends AppHelper {

function fetch($model, $options = null, $fetch = ‘all’) {
App::import(’Model’, $model);
$Model = new $model();
return($Model->find($fetch,$options));
}

}
?>

usage:

add this helper to your controller, i would recommend to add it to the AppController

and just use in your view: $fetcher->fetch(’Users’,array(’conditions’ => ‘client_id’ => 34));

enjoy.

  1. Next post: Javascript – DOM – Convert XML DOM object to friendly array.
  • Thanks for sharing, I really appreciate it your hard work
  • I wanted to thank EVERYONE for these great comments and suggestions,  I'm reading through all of them.
blog comments powered by Disqus