Here is how I go about doing stuff with it. I have my bootstrap file and calls everything and all that figured out no problem. I am also using PHPtal as my templating engine with my own translation system worked in. I have 1 main template class for the different main templates (admin side, users side, and another for different sections) so what really happens when a page is loaded is that the controller for that page loads the inner content, then passes it on to the main template which builds itself and just throws the passed content in the main body of the page. All is well.
Were I think I am having a problem is in my controller section. Here is how a controller of mine might look (this is just a general idea)
Code: Select all
<?php
class NewsController extends Zend_Controller_Action
{
private $NEWS;
private $TEMPLATES;
private $title;
public function init()
{
Zend_Loader::loadClass('News');
$this->NEWS = new News;
Zend_Loader::loadClass('Templates');
$this->TEMPLATES = new Templates;
$this->c = new Zend_View_Phptal;
$this->c->setScriptPath(Zend_Registry::get('config')->paths->view->path);
Functions::loadLanguageFile('user/news/view');
$this->title = '';
}
public function indexAction()
{
$news = $this->NEWS->fetchAll(null, 'id DESC');
if (!count($news))
{
$template['isNews'] = false;
$template['newsContent'] = USERS_ARTICLES_THERE_ARE_CURRENTLY_NO_ARTICLES;
}
else
{
$template['isNews'] = true;
foreach ($news as $headline)
{
$template['newsContent'][] = array(
'headline' => $headline->headline,
'shortStory' => Functions::substrAtWord($headline->short_story, 140),
'viewHref' => 'news/'.$headline->url_headline.'/',
);
}
}
$this->c->set('USERS_NEWS_RAKEBACK_COM_NEWS', USERS_NEWS_RAKEBACK_COM_NEWS);
$this->c->set('USERS_NEWS_READ_MORE', USERS_NEWS_READ_MORE);
$this->c->set('isNews', $template['isNews']);
$this->c->set('newsContent', $template['newsContent']);
try
{
$this->TEMPLATES->main($this->c->render('user/news/index.html'), $this->title);
}
catch (exception $e)
{
dump($e);
die();
}
}
}
What I was doing in my home-grown templating system was I would have the templates then a view class then a controller class then a model class (if that particular section has a table to go with it). I would set all the variables in the view class that would be passed to the template. If someone submitted a forum or passed an action, that action would be processed in the controller class that would do all the other work but wouldn't be loaded unless it was needed. Right now with the larger controllers I am loading a several thousand line file of which very little will be used. It's not so much a problem of file length as it is of maintaining such a huge file. It gets bad, and it was better when things were separate.
A quick skeleton of what a bigger file would look like is this:
Code: Select all
<?php
class UsermapController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
}
public function searchAction()
{
}
public function downloadAsCSVAction()
{
}
public function chooseEmailAction()
{
}
//this method is only called through ajax
public function approveDenyAction()
{
}
public function commentsAction()
{
}
//this method is only called through ajax
public function updateCommentsAction()
{
}
//this method is only called through ajax
public function onHoldAction()
{
}
//this method is only called through ajax
public function updateUsernameAction()
{
}
//this method is only called through ajax
public function updateAdditionalFieldAction()
{
}
//this method is only called through ajax
public function getEmailBodyAction()
{
}
private function _getUserInfoFromQuery($usermap, $show)
{
}
private function _setEmailVariables($email, $fields)
{
}
}
So what would be a better way to go about this? Why does this just feel so dirty to me?