Archive for the ‘Zend Framework’ Category

Jara Base – a base Zend Framework app

Wednesday, January 21st, 2009

I recently had to set up a Zend Framework project at a friend’s house and realized how reliant I am on Zend Studio to set up a fresh project. Meet Jara Base – the ZF starter app and my solution to this minor issue. It’s essentially a slightly modified version of the Zend Studio project structure with the following variations/additions:

  • Added a test helper to the tests folder.
  • Added a static route plugin for handling static site pages.

Usage

Adding static pages

Most applications have pages for static content e.g. an about page, a contact page, etc. I prefer my static pages without the controller name and the ‘page’ route removes the need to add the controller name to the url. Jara Base already includes an about page with a corresponding view and this page is accessed with ‘http://www.example.com/about’ rather than ‘http://www.example.com/index/about’.

To add a static page, add an action to the ‘Index’ controller of the ‘Default’ module. Add a corresponding view and the page will be available at ‘http://www.example.com/:action’.
Static routes with the same name as your controller actions are created by default.
To disable static routes, comment out (or delete) the static routes line in the plugins section of the application config file (application.ini).

Zend Framework titbits

Sunday, January 18th, 2009

There are a couple of Zend Framework snippets and how-tos I find myself googling over and over again. I have decided to maintain this list and keep adding to it as I go along.

  • Bypassing Zend_Db prepared statements:For complex queries, you may have to write the query out by hand and we recently had to do that. However Zend_Db insists on preparing ALL statements and a PDO bug forced the need to bypass this by accessing the connection object directly.
    To do that run:

    $result = $db->getConnection()->exec('SELECT * FROM users');

    More in the documentation

  • Disable Zend_Layout
    public function ajaxAction() {
    // disable layouts for this action:
    $this->_helper->layout->disableLayout();
    ...
    }
    
  • Disable Zend_ViewRenderer
    public function processingAction() {
    $this->_helper->layout->disableLayout();
    
    // disable the view for this action. e.g. actions that redirect after processing
    $this->_helper->viewRenderer->setNoRender();
    ...
    }