使用zend framework 2创建wordpress插件 [英] create wordpress plugin with zend framework 2
问题描述
我想在wordpress下开发一个会员插件,为此,我想使用zend framework2.
I want to develop a membership plugin under wordpress and for this I want to use zend framework 2.
有人使用zend Framework 2创建了一个wordpress插件吗?
我是zf的新手,我不知道从哪里开始.
我尝试从zend骨架应用程序开始,但是陷入了add_menu_pages并显示一个简单的仪表板的问题.
Does anyone managed to create a wordpress plugin using zend framework 2?
I'm new to zf and I do not know how and where to start from.
I tried to start from zend skeleton application but got stuck at add_menu_pages and displaying a simple dashboard.
任何人都可以给我一些想法或链接.
谢谢!
Can anyone give me some ideas or links.
Thanks!
已更新!
我设法使它正常工作!我只需要使用PhpRenderer.对于那些需要更多帮助的人,这里是我的工作方式:
I managed to get this working! I just needed to use a PhpRenderer. For those who need a little more help here is how I did:
我创建了一个用于管理所有管理区域的类.在类初始化时,我调用了一个创建菜单页面的方法(在此方法中,简单地称为add_menu_pages(),而不是callback_function,我调用了一个新方法manage_pages,该方法可以管理页面,但是您可以根据需要进行操作)然后我启动了视图,像这样:
I created a class that manages all admin area. On class init I called a method that created menu pages( in this method simply add_menu_pages() and instead of callback_function I called a new method, manage_pages, that, wel... manages pages, but you can do it as you desire) and then I initiated the view, like this:
$this->view = new PhpRenderer();
$this->map = new Resolver\TemplateMapResolver(array(
'template_name' => 'template_path',
'template2_name'=> 'template2_path')); //this is for handling view templates a little easier
$this->resolver = new Resolver\TemplateMapResolver($this->map);
$this->view->setResolver($this->resolver);
$this->model = new ViewModel();
此外,在manage_pages方法中,对于我拥有的每个页面,我都添加了自己的模板和所需的变量
Further, in manage_pages method, for each page I have, I added its own template and variables I needed
$this->model->setTemplate('template_name');
$this->model->setVariable('variable_name', value);
关于显示模板,您只需要编写以下代码:
As for displaying template, you just have to write this piece of code:
echo $this->view->render($this->model);
在模板文件中,您可以使用$this->variable_name
访问变量
您也可以使用$this->partial( 'template2_name', assoc_arrray_of_variables_to_be_passed_to_template )
插入另一个模板.
In the template files you can access variables using $this->variable_name
Also you can insert another template using $this->partial( 'template2_name', assoc_arrray_of_variables_to_be_passed_to_template )
.
就这样!如果您有任何疑问,请让我知道!
And this is it! If you have any questions, please let me know!
推荐答案
您可以使用一个wordpress插件,在Google上搜索"wopzen2"或"wordpress and zend framework 2集成",通过此解决方案,您可以使用php wordpress代码中的以下代码:
There is a wordpress plugin you can use, search "wopzen2" or "wordpress and zend framework 2 integration" on Google, with this solution, you can use the following code inside the php wordpress code:
global $wpzf2plugin;
$render=$wpzf2plugin->render('/application/index/contactform');
echo $render;
global $wpzf2plugin;
$render=$wpzf2plugin->render('/application/index/contactform');
echo $render;
如果您熟悉zendframework,此代码将调用contactform动作.
This code calls the contactform action, if you are familiar with zendframework I think you are going to understand it.
此插件专用于开发人员.
This plugin is dedicated to developers.
您可以通过支持中心获得免费版本的插件.
You can get a free version of the plugin via support center.
我希望这个答案对您有帮助
I hope this answer can be helpful for you
参考链接: 示例代码
这篇关于使用zend framework 2创建wordpress插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!