Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>(i believe) the file isn't loaded unless the class is used.</p> </blockquote> <p>Correct. That's how autoloading works.</p> <blockquote> <p>My question is what's likely to be the most efficient way to make calls to these helper classes?</p> </blockquote> <p>Efficient, well, what's efficient? Maybe using C/C++ and compiling the stuff. Anyway, let's try:</p> <blockquote> <p>Should I make all methods in a given helper static, </p> </blockquote> <p>No.</p> <blockquote> <p>or maybe use a singleton pattern for the helpers </p> </blockquote> <p>No.</p> <blockquote> <p>or should I just create a new instance wherever it's used (e.g. an instance in the view an instance in the controller...) ?</p> </blockquote> <p>Yes. If you only use them from time to time, that's very efficient because you can make use of anything as you see fit.</p> <p>In case you use the <em>same</em> object more often, pass it around, inject it into other functions as it's needed.</p> <p>This way you will get the most benefit from autoloading.</p> <hr> <p>Helper object that can have multiple helper you can pass around even, will autoload on first access (lazy loading):</p> <pre><code>class Helper { private $helpers = array(); public function __get($name) { $name = strtolower($name); if(!isset($this-&gt;helpers[$name])) { $classname = ucfirst($name).'Helper'; $this-&gt;helpers[$name] = new $classname; } return $this-&gt;helpers[$name]; } } class Controller { private $helper; public function __construct() { $this-&gt;helper = new Helper(); } public function indexAction() { $ingredients = $this-&gt;helper-&gt;something-&gt;getIngredientsList(); .... } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload