【发布时间】:2010-06-27 06:35:30
【问题描述】:
我一直在编写一些创建通用博客的代码。
它的功能很简单,创建帖子,编辑和删除帖子并允许cmets。
我正在尝试编写它以便为它编写插件非常容易,但是我不确定最好的方法。
我的一些想法:
-
让插件作者编写一个名为“config”的简短脚本,其中他们有一个数组,其中包含应用程序(例如前端、管理等)、模块(例如博客、配置文件等)和操作(例如创建,编辑等),他们的插件会影响,然后在运行正确的操作时包含插件文件。
//example array in config.php: array( 'application' => 'admin', 'module' => 'blog', 'action' => array('create','edit') ); -
将字符串添加到视图代码中,例如“{form-extras}”,并让插件作者说出代码将替换哪个字符串。然后使用 str_replace 将 {xxx} 替换为插件代码。
#example code in blog_form.php <input type="text" name="blog_title" /> <input type="text" name="blog_text" /> {form-extras} #example code in plugins config.php array( 'replace' => array('form-extras') );
这两个想法都非常垃圾,而且它们的使用非常有限,但我正在努力想出更好的想法。
我不确定人们需要多少关于我的代码的信息,但基本的目录结构很简单,下面是一个示例:
apps //applications
frontend //app name
modules
blog
views
index.php //list blogs
new.php //create new blog post
actions.class.php
admin
modules
blog
views
index.php //list blogs
new.php //create new blog post
actions.class.php
lib //library of classes like database class
plugins //where plugins will hopefully be installed
web //where the site runs e.g index.php, all the css and js
问题
是否有人知道任何关于使代码易于编写插件的教程/文章,或者是否有人有任何我可以应用的经过测试的方法?
问候
卢克
【问题讨论】:
标签: php model-view-controller plugins