Home » Php » php – Zend Framework, run query without a view?

php – Zend Framework, run query without a view?

Posted by: admin July 12, 2020 Leave a comment


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()

    $oNews = new news();

and this is my model

public function archiveNewsArticle($news_id)
    $db = Zend_Registry::get('db');
    $sql = "UPDATE $this->_name SET live = '0' WHERE news_id = '$news_id' LIMIT 1";
    $query = $db->query($sql);
    $row = $query->fetch();

    return $row;

I would appreciate any help any one can give.



How to&Answers:

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
// Do not even attempt to render a view

This has the added benefit of no overhead of redirection if what you are doing has no output/non-HTML output.


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):


If you are using the layout component of ZF also add this:



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
// 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


after all of your controller job is done.


Orignal Answer:

Your call to:


Calls the Redirector action helper, which (unless you’ve configured it not to) will automatically exit the script as soon as the headers are written, so the view will never be called or rendered, there’s no need for a view script.

Follow-up Answer:

In order to call the action without sending the user to the other “page” and then redirecting back again you’ll need to use an XMLHttpRequest (AJAX) call. These links should provide the information you need:


Also take a look at some JS frameworks that make using XMLHttpRequest cross-browser much easier:


Zend Framework actually has built in support for the Dojo JS framework, which you may find easier: