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.
  • Khozemk

    i have a problem in address field..
    rest all is correct n properly filled by me....
    but i get a problem with address field....i have tried foll address
    username @natrelay.deltathree.com
    username @sip.deltathree.com
    username @sipauth:twitter .deltathree.com
    i hav also tried without username...
    i had al settings installed previously n was working well,,
    now i had formatted the phone,,kept the settings as backup but now they aren't working,,for each and every address mentioned above,the operator says account is not acctive,whereas i use the same account on my PC for making calls.

  • gestudio

    It is just what i've been looking forward for months, i dont understand how this is not present in cakephp built ...

  • Really nice website design, inspiring.. Great Share.

  • 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