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.

5 Thoughts on “Integrating Zend_View with WordPress

  1. Pingback: Kevin Schroeder’s Blog: Integrating Zend_View with WordPress | Development Blog With Code Updates : Developercast.com

  2. Pingback: Kevin Schroeder’s Blog: Integrating Zend_View with WordPress

  3. Pingback: abcphp.com

  4. Pingback: A semana no mundo PHP (25/03/2011) | raphael.dealmeida

  5. BTW, you can simplify your code a little using import statements. I’d suggest the following:

    use Zend_View as ViewEngine,
    Zend_View_Interface as View;

    This will make the code slightly easier to read, document your dependencies, and allow for later substitutions (e.g., when you start using ZF2 in a few months). :)

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation

Web Analytics