FuelPHP - 加载模型
这很可能是我忽略的一个简单答案。
我正在尝试创建一个客户控制器来访问 FuelPHP 中的自定义模型,如下所示:
class Controller_Casting extends Controller
{
public function action_index()
{
Model_casting::author_get();
}
}
class Model_casting
{
## --------------------
public function author_get()
{
$query = DB::query('SELECT * FROM youtube_author');
$result = $query->execute();
print_r($result);
}
}
控制器生成错误:
ErrorException [ Error ]: Class 'Model_casting' not found
在代码点火器中,我必须先加载模型使用它..你如何在 FuelPHP 中做同样的事情(我认为这就是问题所在)..
谢谢,
this is most likely a simple answer that i have overlooked..
I am trying to create a customer controller that accesses a custom model in FuelPHP as follows:
class Controller_Casting extends Controller
{
public function action_index()
{
Model_casting::author_get();
}
}
class Model_casting
{
## --------------------
public function author_get()
{
$query = DB::query('SELECT * FROM youtube_author');
$result = $query->execute();
print_r($result);
}
}
An error is generated by the controller:
ErrorException [ Error ]: Class 'Model_casting' not found
In code igniter i would have to load the model before using it.. How do you do the same thing in FuelPHP (which i presume is where the issue lies)..
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
还有一件事。类名是否应始终采用 Model_Casting 格式。第一个字母大写,后面的“_”也大写。只是一个提示!
Also one more thing. If class names should always be formatted like Model_Casting. First letter uppercase and after a '_' also uppercased. Just a tip!
好吧,问题似乎解决了..我在模型前面加上了“model”前缀..
Ok, problem solved it would seem.. I was prefixing the model with "model"..
您需要使用命名空间 Model 和 DB,尝试扩展 Model 类。
这是模型文件的新代码。
You need use namespace Model and DB, try to extends Model class.
This is the new code for Model file.