dongwaner1367 2013-09-27 02:58
浏览 42
已采纳

codeIgniter中的函数帮助与另一个函数冲突

In codeIgniter I auto load the url_helper.php
In my site I also have a phpbb forum and so within codeigniter im trying to include a script from the forum.

The problem is, phpbb tries to declare a function redirect() but its already declared in the url_helper.php so i get the following error

Cannot redeclare redirect() (previously declared in C:\Apache24\htdocs\system\helpers\url_helper.php:531) in C:\Apache24\htdocs\forum\includes\functions.php on line 2562

What can I do go go around this? Can I unset the function or remove the url_helper entirly in my controller function?

  • 写回答

2条回答 默认 最新

  • dongyuxin5353 2013-09-27 03:30
    关注

    Ok, I got a work around. In the codeigniter's helper library, before declaring a function, it first checks if it has been declared before or not. So....

    In my controller class's constructor method, I load all the phpbb files I need. this way it declares the phpbb redirection function and codeigniter goes "ohh there is already a redirect function" and so it doesn't declare the redirect function... Problem solved

    Something like this:

    class Register extends CI_Controller{
    
        public function __construct()
        {
            /* START phpbb */
            .
            .
            .
            require_once('forum/common.php');
            require_once('forum/includes/functions_user.php');
            require_once('forum/includes/functions_module.php');
            /* END phpbb */        
    
            //Continue as normal
            parent::__construct();
        }
    
        public function index(){
            //Your stuff works as normal now
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?