Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up finding the answer to my own question through more debugging (I previously hadn't had ini_set('display_errors', '1'); set - silly me).</p> <p>The proper syntax to add a class to the ZF2 ServiceManager (within your Module.php) appears to be:</p> <pre><code>public function getServiceConfiguration() { return array( 'factories' =&gt; array( 'album-table' =&gt; function($sm) { $dbAdapter = $sm-&gt;get('db-adapter'); $table = new AlbumTable($dbAdapter); return $table; }, 'test-model' =&gt; function($sm){ return new Model\TestModel; }, ), ); } </code></pre> <p>And just for completeness, in order to call a method from the class you're including you can use this in your controller file (DashboardController.php in my case) as long as you're extending the ActionController class:</p> <pre><code>class DashboardController extends ActionController { public function indexAction() { return new ViewModel(array( 'users' =&gt; $this-&gt;getTestModel()-&gt;testMethod(), )); } public function getTestModel() { if (!$this-&gt;testModel) { $sm = $this-&gt;getServiceLocator(); $this-&gt;testModel = $sm-&gt;get('test-model'); } return $this-&gt;testModel; } } </code></pre> <p>Where testMethod() is a method from within the TestModel class. Some notes from this for anybody new to Zend or namespaces - one of my issues was that I was using the full class name reference (Dashboard\Model\TestModel) when I had set the namespace at the top of the file to Dashboard, so the first Dashboard was unnecessary and caused PHP to look for Dashboard\Dashboard\Model\TestModel. Also, as of this writing sample ZF2 module are scarce - I recommend looking to samples like ZfcUser by EvanDotPro for examples on this type of thing.</p> <p>My original confusion about the various sub-keys for adding classes to the ServiceManager still lingers though, so if you have any insight as to that I will continue to monitor this question and will mark your answer as "the" answer should you solve that bit, thank you :).</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      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