【问题标题】:Access data from setting Model cakePHP从设置模型 cakePHP 访问数据
【发布时间】:2012-07-20 15:29:39
【问题描述】:

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

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

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

     $this->Post->read()

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

例如如果 Post['submitted_by'] = $this->Auth->user('role') == 'admin') "伪代码"

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    试试这个代码:

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

    【讨论】:

      【解决方案2】:

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

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

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

      这段代码修改了视图实例,仅此而已。您需要另一个函数将视图链接到数据库。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-25
        • 1970-01-01
        相关资源
        最近更新 更多