如何在 Kohana 3 中使用自定义库
我试图包含一个用户库,其中包含一些与用户相关的功能,例如检查用户是否经过身份验证等。现在我正在尝试使用 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;
但它似乎没有成功。
如何调用自定义库?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将库放置在
/application/classes/
中。否则,您必须将其放入控制器中:
您可以在此处阅读有关此内容的信息。
现在您可以像以前一样,在目录
library
中使用User.php
。Place the library in
/application/classes/
.Otherwise, you have to place this in your controller:
You can read about this here.
Now you can do the same as before, with
User.php
inside the directorylibrary
.