Running Zend Framework MVC in your plain ol’ PHP project

It’s nice being able to use some of the features of Zend Framework in your old plain PHP projects. I’ve been doing this for a while, using a zend_init.php file which is almost like the index.php in the ZF public folder:

// Define path to application directory
 || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application/application'));

if($_SERVER['SERVER_ADDR'] == '')
 $app_env = 'production';
 $app_env = 'development';

// Define application environment
 || define('APPLICATION_ENV', $app_env);
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
 realpath(APPLICATION_PATH . '/../library'),
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
 APPLICATION_PATH . '/configs/application.ini'

That allows you to use all sorts of things like new Zend_Pdf() etc.
However I was doing an AJAX post from our plain old PHP site and I wanted it to actually run the MVC stuff!

In order to run controller actions from a plain script I did this:

$fc = Zend_Controller_Front::getInstance();
$request = new Zend_Controller_Request_Http();
 'module' => 'default',
 'controller' => 'branches',
 'action' => 'cms-save-branch-update'

You now have the full power of Zend Framework at your disposal! Have a nice day!


3 thoughts on “Running Zend Framework MVC in your plain ol’ PHP project

  1. Avec une composition pareille, je pense que je tenterais le lavage à la main, voire machine à basse T) et sur "délicat", sans essorage…Je n'étais pas sûre pour la robe d'Eleonore, me souvenais pas de la marque de la sienne, mais finalement si.

  2. got me to thinking about what if the population was only 10% of current numbers, might be a positive thing. So how are we going to tell the other 90% they gotta go? (LOL) As to these 2 clowns shooting? The one fella definitely needs a SERIOUS talking to about range safety, and what an idiot he is, possible punctuated with a couple of smacks upside his head.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s