Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在同一控制器中使用其他模型?CAKEPHP_Cakephp - Fatal编程技术网

如何在同一控制器中使用其他模型?CAKEPHP

如何在同一控制器中使用其他模型?CAKEPHP,cakephp,Cakephp,就像我有一个posts表,我为r/w数据构建了一个postscontroller和一个Post模型,但是如果我还希望r/w数据到另一个名为users的表呢?我构建了另一个名为user的模型,如何从postscontroller中的users表中获取数据?您可以在控制器下阅读手册,这就是您要查找的内容,或者搜索stack exchange以获取答案,甚至用谷歌搜索答案。有两种方法可以做到这一点: // Call in Controller's methods to load dynamically

就像我有一个posts表,我为r/w数据构建了一个postscontroller和一个Post模型,但是如果我还希望r/w数据到另一个名为users的表呢?我构建了另一个名为user的模型,如何从postscontroller中的users表中获取数据?

您可以在控制器下阅读手册,这就是您要查找的内容,或者搜索stack exchange以获取答案,甚至用谷歌搜索答案。

有两种方法可以做到这一点:

// Call in Controller's methods to load dynamically model Article and set it to $this->User 
$this->loadModel('User');

// Add this variable as Controller's property and get $this->Post and $this->User accessible
var $uses = array('Post','User');
阅读更多关于和的信息