我正在尝试通过http://codeigniter.com/forums/viewthread/109584/P20上的wiredesignz 设置小部件插件,但我不断收到错误消息。我很确定我已经按照线程中的指示进行了所有设置,但是当我<?php widget::run("test"); ?>
在我的视图中尝试时,我得到了以下信息:
class Test extends Widget { function run() { echo "test"; } }
Fatal error: Class 'Test' not found in C:\xampp\htdocs\test\application\helpers\widget_helper.php on line 52
我能想到的唯一与我的安装不同的是,我使用的是 Phil Sturgeon 的模板库。
以下是我如何构建所有内容:
/application/helpers/widget_helper.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Widget Plugin
*
* Install this file as application/plugins/widget_pi.php
*
* @version: 0.21
* $copyright Copyright (c) Wiredesignz 2009-09-07
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
class Widget
{
public $module_path;
function run($file) {
$args = func_get_args();
$module = '';
/* is module in filename? */
if (($pos = strrpos($file, '/')) !== FALSE) {
$module = substr($file, 0, $pos);
$file = substr($file, $pos + 1);
}
list($path, $file) = Modules::find($file, $module, 'widgets/');
if ($path === FALSE) {
$path = APPPATH.'widgets/';
}
Modules::load_file($file, $path);
$file = ucfirst($file);
$widget = new $file();
$widget->module_path = $path;
return call_user_func_array(array($widget, 'run'), array_slice($args, 1));
}
function render($view, $data = array()) {
extract($data);
include $this->module_path.'views/'.$view.EXT;
}
function load($object) {
$this->$object = load_class(ucfirst($object));
}
function __get($var) {
global $CI;
return $CI->$var;
}
}
/application/widgets/test.php
class Test extends Widget {
function run() {
echo "test";
}
}
/application/views/layouts/public.php
<?php widget::run("test"); ?>
知道如何让这个工作吗?这只是过时了吗?
我一直在寻找更好的解决方案来做小部件,但我似乎找不到任何东西。我只需要能够逐页控制站点侧边栏上显示的内容。有没有替代方法?
编辑:错误来自评论中的小部件库
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Lang::$active_lang
Filename: libraries/widgets.php
Line Number: 26
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Page::$sys_lib
Filename: libraries/widgets.php
Line Number: 87
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/widgets.php
Line Number: 27
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Lang::$active_lang
Filename: libraries/widgets.php
Line Number: 26
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Page::$sys_lib
Filename: libraries/widgets.php
Line Number: 87
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/widgets.php
Line Number: 27