【发布时间】:2016-04-12 12:25:41
【问题描述】:
我尝试在自定义助手中创建新方法,
if ( ! function_exists('active_link'))
{
function active_link($method_name)
{
if($CI->router->fetch_method()==$method_name){
return 'active';
}
return 'none';
}
}
代码不起作用,因为我无法通过 CI 实例获取路由器。
遇到 PHP 错误严重性:错误
消息:调用成员函数 fetch_method() on null
文件名:helpers/smart_helper.php
行号:8
【问题讨论】:
-
我想你忘了
$CI =& get_instance();里面的助手!! -
不,我已经这样做了,但它不起作用。
-
<?php if ( !defined('BASEPATH')) exit('不允许直接脚本访问'); $CI =& get_instance(); if (!function_exists('active_link')) { function active_link($method_name) { if($CI->router->fetch_method()==$method_name){ return 'active'; } 返回“无”; } }
标签: php codeigniter helper