Zend Framework, run query without a view?
Solution 1
I use this with calls to AJAX-only actions that I either don't want output or I'm using some other output, like XML or JSON:
// Disable the main layout renderer
$this->_helper->layout->disableLayout();
// Do not even attempt to render a view
$this->_helper->viewRenderer->setNoRender(true);
This has the added benefit of no overhead of redirection if what you are doing has no output/non-HTML output.
Solution 2
To disable view rendering in an action (put this in the specific action. If you want it for the entire controller put it in the init method):
$this->_helper->viewRenderer->setNoRender();
If you are using the layout component of ZF also add this:
$this->_helper->layout->disableLayout();
Solution 3
I could not figure out your code there. in your model you are calling die(). why? it will stop the execution. are you sure about that line? anyway, if you have a controller in Zend Framework and do not need any view, you can turn the view off by this line:
// code in your controller
$this->_helper->viewRenderer->setNoRender(true);
// the rest of the controller
now the controller will not search for a view script to show to the user. make sure you will call
$this->_redirect()
after all of your controller job is done.
Admin
Updated on June 16, 2022Comments
-
Admin almost 2 years
I am currently building a small admin section for a website using Zend Framework, this is only my second time of using the framework so I am a little unsure on something things. for example are I have an archive option for news articles where the user will hopefully click a link and the article will be archived however I cannot work out how to get this to run without having a view?
this is my controller
public function archiveNewsAction() { //die(var_dump($this->_request->getParam('news_id'))); $oNews = new news(); $this->_request->getParam('news_id'); $oNews->archiveNewsArticle($news_id); //die(var_dump($oNews)); $this->_redirect('/admin/list-all'); }
and this is my model
public function archiveNewsArticle($news_id) { //die($news_id); $db = Zend_Registry::get('db'); $sql = "UPDATE $this->_name SET live = '0' WHERE news_id = '$news_id' LIMIT 1"; die($sql); $query = $db->query($sql); $row = $query->fetch(); return $row; }
I would appreciate any help any one can give.
Thanks
Sico
-
Admin about 15 yearsThanks what I am trying to do though is stop the linking following a path though and just wanting archive the news article, without having to navigate to another a view, how to inisiate the query?