Zend Framework

Doctrine Generate Models from DB

Automatically generating the models for a project based off of existing database tables is extremely handy. I’ve had to do this several times and the available options are key, especially when generating these for a Zend Framework layout. The following stack overflow entry is very helpful:


* Doctrine CLI script

define('APPLICATION_ENV', 'development');

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../library/Doctrine'),

require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_PATH . '/config/default.ini'


APPLICATION_PATH . '/modules/default/models/DbTable',
'pearStyle' => true,
'generateTableClasses' => true,
'baseClassesDirectory' => '',
'classPrefix'=> 'Model_DbTable_',
'classPrefixFiles' => false,
'baseClassPrefix' => 'Generated_'

Tuesday, November 15th, 2011 Doctrine, Zend Framework No Comments

Disable the View/Layout in Zend Framework

Use the following snippet to disable the view/layout in the Zend Framework:

class IndexController extends Zend_Controller_Action
    public function init()
        // Disable render helper and zend Layout
Monday, April 26th, 2010 Zend Framework No Comments

SOAP Authenticatation using Soap Headers – API Class, Client, Server & WSDL Generation Examples

So about a week ago I needed to put together a SOAP service and wanted to make sure that not just anyone would be able to access the services. So I set about and scanned many pages in my google searches and have finally come to a working example. Hopefully you will find this page relatively quickly and save yourself the same nearly endless searches.

First let’s go ahead and create the server side of the service. I have posted the example of this code earlier on in another SOAP tutorial, but I will go ahead and throw it in here as well.
› Continue reading

Tuesday, January 5th, 2010 API Services, Zend Framework 5 Comments

Auto-Generating a SOAP WSDL using the Zend Framework

WSDL’s are not fun to make by hand. If you have to make a change or add a function, the slowest part would be adding it to the WSDL. Luckily the Zend Framework has allowed us to speed things up a bit by auto-generating the WSDL based on a class that is passed.

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('YourClassName','', null,$_SERVER['PHP_SELF']);

Now if you go to where you have this file located, let’s say:


You can then take a look at it!

Now, normally you will want to wrap this together with the server itself. To do so you would need to add a few more lines of code.
› Continue reading

Tuesday, December 29th, 2009 API Services, Zend Framework No Comments

Integrating ZFDebug and Doctrine Query Profiling into your Zend Application

This past week I noticed that one of my applications was running extremely slow. Now I still don’t know why it wasn’t so slow before I had made the fix I am about to explain, but the point of this post is – ZFDebug is AWESOME!

Here is how to implement it in a Zend_Application environment (the site also has examples) -
› Continue reading

Tuesday, November 3rd, 2009 Zend Framework 1 Comment

Zend Framework – Disable Layout for exporting CSV file

I am using a plugin to pull up my layouts specific to the module that the user is in. I needed to be able to disable the layout, but still render the view because the view was where I compile the entire report for our company.

Here is my Layout Plugin:

class Plugin_Layout extends Zend_Controller_Plugin_Abstract
    public function preDispatch(Zend_Controller_Request_Abstract $request)
        $module = $request->getModuleName();

        $front_controller = Zend_Controller_Front::getInstance();
        $error_handler = $front_controller->getPlugin('Zend_Controller_Plugin_ErrorHandler');
    public function postDispatch(Zend_Controller_Request_Abstract $request)

        $front_controller = Zend_Controller_Front::getInstance();
        $module_directory = $front_controller->getModuleDirectory();
        $layout = Zend_Layout::getMvcInstance();
        $layout->setLayoutPath($module_directory . DIRECTORY_SEPARATOR . 'views/layouts');
        if(isset($_REQUEST['format']) && $_REQUEST['format'] != 'html') {


You can see that inside my postDispatch method I have included that if there is a request variable set to ‘format’ (that is Post/Get/Cookie) and it is not equal to ‘html’, then it will render the page without a layout. By doing this it allows me to easily add other reports that are not created for use with an MVC structure, quickly and effortlessly – in many cases what you may do instead is set the layout disabling inside a particular action and also disable the view, but because the reports contain the data that creates the CSV I need the view to Render. Any questions or comments – feel free to leave a note!

Friday, October 23rd, 2009 Zend Framework No Comments

Zend Framework – Adding Custom Layouts for Each Module

There are several sources out there that explain how you can create a layout for each module, however, none that I have found did it quite right.
› Continue reading

Thursday, September 17th, 2009 Zend Framework 1 Comment

Zend Framework – Adding Doctrine ORM into Zend Framework 1.8+

I will add more details as to add things to your application.ini file, but for now

I want to record some OS specific notes – namely for those using Mac OSX.

I kept getting the error:
‘Couldn’t locate driver named mysql’

I ran into this problem when I was trying to create models from the command line (terminal).

My php.ini in MAMP was including the pdo_mysql.so – so I didn’t understand what in the world was going on. After a bit of searching I got the idea that it was using the base PHP included with the OS instead of my installed MAMP installation – sure enough that was it.

So in the terminal I needed to make sure I was running the MAMP version of php by pre-fixing my command with:

Instead of: php

Then everything was happiness and glory.

More to come… I’m just starting with this.

Thursday, August 27th, 2009 Doctrine, Zend Framework No Comments

Zend Framework – Creating Access Control for your Applications – Zend_ACL

I plan on extending more on this topic as well, but wanted to make a note.

It may be obvious.. but it took me awhile to figure out how I could specify access to a particular action inside of a controller.

Hopefully, I was the only one – but just in case ;) here ya go!

        const ROLE_GUEST = 'guest';
        const ROLE_USER  = 'user';
        const ROLE_ADMIN = 'admin';

        $this->_acl = new Zend_Acl();

        // define our possible user groups
	$this->_acl->addRole(new Zend_Acl_Role(self::ROLE_GUEST));

	// members have at least same access as guest
	$this->_acl->addRole(new Zend_Acl_Role(self::ROLE_USER), array(self::ROLE_GUEST));

        // admins have at least same access as users
        $this->_acl->addRole(new Zend_Acl_Role(self::ROLE_ADMIN), array(self::ROLE_USER));

	// define our restricted controllers as resources.
        $this->_acl->add(new Zend_Acl_Resource('modulename'));
        $this->_acl->add(new Zend_Acl_Resource('modulename/controllername'));
        $this->_acl->allow(self::ROLE_USER,  'modulename');
        $this->_acl->allow(self::ROLE_USER,  'modulename/controllername', 'actionname');
        $this->_acl->allow(self::ROLE_ADMIN, null, array('actionname'));
Friday, August 21st, 2009 Zend Framework No Comments

Zend Framework – Taking advantage of Zend_Application to create Modularity

Over the past few days I have been looking to integrate the latest features of the Zend Framework, namely Zend_Application and using Bootstrap classes inside modules…
› Continue reading

Friday, August 21st, 2009 Zend Framework No Comments
[ad code=1 align=center]