从设置Model cakePHP访问数据

时间:2012-07-20 06:47:05

标签: php cakephp

如果我在控制器中设置Post模型,如下所示;

    $this->Post->id = $id;

我可以从Post访问数据还是必须执行执行;

     $this->Post->read()

我想在Post上进行一些进一步的验证,以确定正在执行的逻辑。

e.g。如果帖子['submitted_by'] = $ this-> Auth->用户('角色')=='admin')“伪代码”

2 个答案:

答案 0 :(得分:0)

尝试此代码:

$data = $this->Post->read(null, $id)

答案 1 :(得分:0)

您必须阅读()才能访问数据。

这是MVC的工作方式(more info there)。

$this->Post->id = $id;

此代码修改了视图实例,这就是全部。您需要另一个函数将视图链接到数据库。

相关问题