CakePHP 2.0:通过 AppController 为 Helper 准备来自不同模型的数据?
我制作了一个助手,它应该在布局中从我的数据库输出一些数据,因此这些数据必须在任何地方都可用。现在我尝试通过 AppController 加载和设置变量,但似乎我无法使用通常的 find() 方法。这是我的错误:
Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\propfe\Controller\AppController.php on line 46
这就是我尝试加载模型的方式,一次通过 $uses-variable,一次通过 App::import()-Command:
var $uses = 'Surgeryhour';
App::import('Model','Surgeryhour');
这是错误的第 46 行:
$this->set('data', $this->Surgeryhour->find(null, '1'));
任何想法如何我可以获得所有这些去工作?
I've made a helper, that should output some data from my database in the layout, so this data have to be available everywhere. Now I tried to load and set a variable by the AppController, but it seems I can not use the usual find()-method. Here's my error:
Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\propfe\Controller\AppController.php on line 46
That's how I tried to load the Model, once by the $uses-variable and once by the App::import()-Command:
var $uses = 'Surgeryhour';
App::import('Model','Surgeryhour');
And here's the line 46 of the error:
$this->set('data', $this->Surgeryhour->find(null, '1'));
Any ideas how I can get all this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试像这样加载模型:
不需要变量
$uses
。Try load model like this:
Don't need variable
$uses
.永远不要对模型使用 App::import
:
never use App::import for models
always: