如何在codeigniter中的路由文件中使用helpers函数


How to use helpers function inside route file in codeigniter

我想在codeigner中加密url,我在helper中创建了一个函数encode_url(),并使用codeigner加密库对其进行解码,我添加了链接作为encode_url["home"],并想将此url路由到home控制器,但我无法访问路由文件中的helper函数。有没有任何方法可以使用解码函数路由url,或者我必须在控制器中创建新的函数并在那里解码
辅助中的编码功能

function encode_url($string, $key="", $url_safe=TRUE)
{
if($key==null || $key=="")
{
    $key="sh_hebrewurlencryption";
}
  $CI =& get_instance();
$ret = $CI->encrypt->encode($string, $key);
if ($url_safe)
{
    $ret = strtr(
            $ret,
            array(
                '+' => '.',
                '=' => '-',
                '/' => '~'
            )
        );
}
return $ret;
}

助手中的解码功能

function encode_url($string, $key="", $url_safe=TRUE)
{
if($key==null || $key=="")
{
    $key="sh_hebrewurlencryption";
}
  $CI =& get_instance();
$ret = $CI->encrypt->encode($string, $key);
if ($url_safe)
{
    $ret = strtr(
            $ret,
            array(
                '+' => '.',
                '=' => '-',
                '/' => '~'
            )
        );
}
return $ret;
}

和菜单中的url类似

<?php echo site_url();?>he/<?php echo encode_url('checkMemberStatus'); ?>

您需要首先在函数中加载助手,然后才能使用它

$this->load->library('encryption');

参考资料可在官方代码点火器上找到