How use custom libraries in Kohana 3

南笙酒味 提交于 2019-12-11 03:19:40

问题


I am trying to include a user library that includes some user related functions such as checking if the user is authenticated and such. Now I am trying to make usage of the Kohana autoloader, but can't seem to get it working.

I have the library placed under application/classes/library

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

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

And I try to call the library with

$user = new User;

But it doesn't seem to do the trick.

How can I call a custom library?


回答1:


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.



来源:https://stackoverflow.com/questions/4767991/how-use-custom-libraries-in-kohana-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!