stone_fine 发表于 2010-11-8 10:48:21

CodeIngiter中使用hooks报$db错误

本帖最后由 stone_fine 于 2010-11-8 11:23 编辑

我在CodeIngiter中使用hooks实现多语言切换,但是当加载hooks时就报Message: Undefined property: Membership_model:$db错误,这是为什么,谢谢各位啊。但是把hooks去掉就正常,而且我在autoload.php中也加载了database.


挂钩点文件Languageclass.php,以下是代码:

<?php

class LangClass extends Controller {

    function set_lang() {

                $my_lang = $this->uri->segment(1);

                if ($my_lang=='english' || $my_lang=='chinese')
                {
                        $this->config->set_item('language', $my_lang);
                }

    }

}


hooks.php中的代码:
<?php
$hook['pre_controller'] = array(
                              'class'    => 'LanguageClass',
                              'function' => 'set_lang',
                              'filename' => 'Langclass.php',
                              'filepath' => 'hooks',
                              );

Controller中的代码:
<?php
class Blog extends Controller {
    function Blog() {
      parent::Controller();
    }
    function index() {
      $this->load->model('Article_model');
      $this->lang->load('blog');
      $data['title'] = lang('blog_title');
      $data['heading'] = lang('blog_heading');
      $data['copyright'] = lang('blog_copyright');
    }
}


Hex 发表于 2010-11-8 10:58:42

贴代码。

不是所有挂钩点都可以操作 database 类库的。

lamtin 发表于 2010-11-8 13:28:03

http://codeigniter.org.cn/user_guide/general/hooks.html
看挂勾点那里
页: [1]
查看完整版本: CodeIngiter中使用hooks报$db错误