Zend_Controller_Action_Helper_ModelLoader aims to allow module based systems load model files from within its own module as well as outside modules. This will promote best practices within the Zend Framework.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
<p>What about the ability to load models that may exist in other modules? For example, what if I'm trying to load a model named "Users" which is located in the "Forum" module? Would I be able to do something like...</p>
<p>It looks to me as if you'd express that as:</p>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$this->_helper->ModelLoader('Users', '/path/to/application/forum/models');
]]></ac:plain-text-body></ac:macro>
<p>...but I haven't verified that yet <ac:emoticon ac:name="smile" /></p>
<p>I'm using this in my current project and you hit the nail right on the head (at least with the copy I'm using).</p>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$this->_helper->ModelLoader('Forum_Users');
]]></ac:plain-text-body></ac:macro>
<p> would indeed load a model named "Users" from the "Forum" module.</p>
<p>I have a question I've been wondering about. Why make it an Action Helper? Surely you want to be able to utilize the loader within your model layer as well? I know I do. <ac:emoticon ac:name="smile" /> If you adhere to the principles of MVC even the view layer should be able to read from the model layer, and would need access to the loader.</p>
<p>Why not just do something similar to Zend_Loader/PluginLoader? That way you can access it from wherever you want to. Could add an autoloader as well that could be registred in the boostrap or similar for autoloading of models.</p>
<p>I'm sure you thought of using Zend_Loader, so I'm curious to know why you went with an Action Helper instead?</p>
6 Comments
comments.show.hideAug 21, 2007
Geoffrey Tran
<p>ralph, validModule = $this->_request->getModuleName(); should be $this->getRequest() since $this->_request needs to be populated first</p>
Nov 02, 2007
Sean St. Heart
<p>What about the ability to load models that may exist in other modules? For example, what if I'm trying to load a model named "Users" which is located in the "Forum" module? Would I be able to do something like...</p>
<p>$this->_helper->ModelLoader('Forum_Users'); </p>
<p>Sorry if this should be obvious, but I'm just looking for clarification. </p>
Nov 02, 2007
Simon Mundy
<p>It looks to me as if you'd express that as:</p>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$this->_helper->ModelLoader('Users', '/path/to/application/forum/models');
]]></ac:plain-text-body></ac:macro>
<p>...but I haven't verified that yet <ac:emoticon ac:name="smile" /></p>
Nov 02, 2007
Simon Mundy
<p>...or...</p>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$this->_helper->ModelLoader('Users', null, 'forum');
]]></ac:plain-text-body></ac:macro>
Nov 03, 2007
Aaron Heimlich
<p>I'm using this in my current project and you hit the nail right on the head (at least with the copy I'm using).</p>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$this->_helper->ModelLoader('Forum_Users');
]]></ac:plain-text-body></ac:macro>
<p> would indeed load a model named "Users" from the "Forum" module.</p>
May 14, 2008
Jens Ljungblad
<p>I have a question I've been wondering about. Why make it an Action Helper? Surely you want to be able to utilize the loader within your model layer as well? I know I do. <ac:emoticon ac:name="smile" /> If you adhere to the principles of MVC even the view layer should be able to read from the model layer, and would need access to the loader.</p>
<p>Why not just do something similar to Zend_Loader/PluginLoader? That way you can access it from wherever you want to. Could add an autoloader as well that could be registred in the boostrap or similar for autoloading of models.</p>
<p>I'm sure you thought of using Zend_Loader, so I'm curious to know why you went with an Action Helper instead?</p>