Integrating Zend_View with WordPress

I just read a blog post about integrating Zend Framework and WordPress and figured I’d add some commentary of my own, since I’ve done something similar.  In my ESchrade plugin I use Zend_View to render some of my admin pages, though there is no reason why you couldn’t use it elsewhere, as long as the plugin has already been loaded.

Getting Zend Framework set up with WordPress is super simple.  Assuming you have Zend Framework already in your include path all you need to do is put the autoloader in your plugin file.

Here is a very slimmed down version of my plugin class that integrates with WordPress.  From the Zend_View perspective, all it really does create a new view object and set it up.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace com\eschrade;
 
class Application
{
/**
*
* @var \Zend_View
*/
private $view;
public function __construct()
{
$this->view = new \Zend_View();
$this->view->setScriptPath(
realpath(__DIR__ . '/../../../templates')
);
$widget = new Popular($this->view);
wp_register_sidebar_widget('popular-posts', 'Popular Posts', array($widget, 'handle'));       
}
 
public function setView(\Zend_View_Interface $view)
{
$this->view = $view;
}
 
public function getView()
{
return $this->view;
}
 
public function handleJobs()
{
$this->view->jobs = new Jobs();
$this->view->jobs->setAction('/wp-admin/plugins.php?page=eschrade-config&action=Run Job');
$this->view->jobs->setMethod('POST');           
$this->view->jobs->setView($this->view);
// cut
echo $this->view->render('admin/runjobs.phtml');
}
}

Obviously you don’t have the view renderer set up, or some of the controller helpers that are so useful, but if you want access to anything that Zend_View has to offer it is thuper eathy to do.

About the author

Kevin Schroeder

View all posts

5 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *