【发布时间】:2014-04-28 00:01:21
【问题描述】:
我在 MySQL“posts_tags”上有表,我想在控制器的 View 操作中获取表行,但我不知道如何?
【问题讨论】:
我在 MySQL“posts_tags”上有表,我想在控制器的 View 操作中获取表行,但我不知道如何?
【问题讨论】:
假设您已经为 posts_tags 表设置了模型,您可以使用 CakePHP 的 find() 完成此操作。
在您的 PostsTagsController 中,它应该如下所示:
<?php
class PostsTagsController extends Controller {
public function myAction(){
// Now you should chose which find suits you: 'all', 'list' or 'first'
$allData = $this->PostsTag->find('all', array(
// Here you set up all options and conditions for your data fetch
// See the above find() reference link for these options
));
//$allData = $this->PostsTag->find('list');
//$allData = $this->PostsTag->find('first');
// Now you should send the data to your View
$this->set('dataInView', $allData);
// In your view, try to print_r($dataInView) and you'll see all the records fetched
}
}
【讨论】: