Anyway, my problem has come into play when developing large systems where certain models will have methods that are very similar across multiple classes. For instance, lets say I want to display news, there will be the news page which it is listed as well as the admin page to modify the information. Obviously we don't want to have duplicate code in our codebase, so how do you guys tackle this problem? I'll give a bit a code in a moment to further illustrate my problem. Just for notes, this is very simplified for those who are wondering.
So we have our init method which is automatically executed for our system startup, making all unnecessary initializations for our application. So in this case, our model is loaded depending on the controller loaded. Application_Controller_Index()'s model becomes Application_Model_Index(). Now since the model is loaded automatically at runtime, I can't determine whether the controller has anymore dependencies, at least not transparently.
<?php
Code: Select all
abstract class Application_Controller extends Zend_Controller_Action
{
function init()
{
$model = $this->formatName($this->_getController());
$this->model = new $model;
}
}Code: Select all
class Application_Controller_Index extends Application_Controller
{
public function IndexAction()
{
$this->view->paintNews($this->model->getNews(5));
}
}
class Application_Controller_NewsManager
{
public function IndexAction()
{
$this->view->paintNews($this->model->getNews());
}
}Thanks.