Php 如何通过ci实例使用codeigniter helper内的路由器,如$ci->;路由器->;fetch_方法()
我尝试在自定义助手中创建新方法,Php 如何通过ci实例使用codeigniter helper内的路由器,如$ci->;路由器->;fetch_方法(),php,codeigniter,helper,Php,Codeigniter,Helper,我尝试在自定义助手中创建新方法, if ( ! function_exists('active_link')) { function active_link($method_name) { if($CI->router->fetch_method()==$method_name){ return 'active'; } return 'none'; }
if ( ! function_exists('active_link'))
{
function active_link($method_name)
{
if($CI->router->fetch_method()==$method_name){
return 'active';
}
return 'none';
}
}
代码不起作用,因为我无法通过CI实例获取路由器
遇到一个PHP错误
严重性:错误消息:调用成员函数
null上的fetch_method()文件名:helpers/smart_helper.php
电话号码:8
使用
而不是
$CI->router->fetch_method()
通过将路由器的请求移动到视图并将两个参数传递给函数,我解决了这个问题: 在助手中
<?php
if ( ! function_exists('active_link'))
{
function active_link($feched_method,$method_name)
{
if($feched_method==$method_name){
return 'active';
}
return false;
}
}
我想你忘了$CI=&get_instance()代码>内部帮助程序!!不,我已经这样做了,但它不起作用。
<?php
if ( ! function_exists('active_link'))
{
function active_link($feched_method,$method_name)
{
if($feched_method==$method_name){
return 'active';
}
return false;
}
}
<?php echo active_link($this->router->fetch_method(),'index');?>