2

我正在尝试包含一个用户库,其中包含一些与用户相关的功能,例如检查用户是否经过身份验证等。现在我正在尝试使用 Kohana 自动加载器,但似乎无法正常工作。

我将库放在 application/classes/library 下

class User {
 public function is_alive()
 {
   $session = Session::instance();
   $data = $session->get('alive');

   if(isset($data))
   {
    return true;
   }
   else
   {
    return false;
   }
 }
}

我试着用

$user = new User;

但这似乎没有奏效。

如何调用自定义库?

4

1 回答 1

3

I have the library placed under application/classes/library

Place the library in /application/classes/.

Otherwise, you have to place this in your controller:

public function before() {
    require Kohana::find_file('classes', 'library/User');
}

You can read about this here.

Now you can do the same as before, with User.php inside the directory library.

于 2011-01-22T15:57:16.690 回答