【问题标题】:CakePHP, getting another models info into the page controllerCakePHP,将另一个模型信息获取到页面控制器中
【发布时间】:2012-08-03 10:23:10
【问题描述】:

我正在尝试使用页面控制器和 admin_index() 函数构建管理页面。我需要获取具有特定状态的所有帖子的列表并将它们显示在此页面上。我怎样才能在页面控制器中抓取这些,以便我可以在视图中显示它们。

非常感谢。

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    试试这个:

    $this->loadmodel('Post');
    $posts = $this->Post->find('all',array('conditions'=>array('Post.id'=>'1','Post.field'=>'value')));
    $this->set('posts',$posts);
    

    【讨论】:

      【解决方案2】:

      您可以在 PagesController 的 admin_index() 函数中加载模型:

      $this->loadModel('Post');
      $posts = $this->Post->find('all', array(
          'conditions' => array('Post.status' => 'your_filter')
      );
      $this->set(compact('posts'));
      

      现在您的页面视图文件中有 $posts 可用。 (根据您的需要调整查找方法)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-12
        • 1970-01-01
        • 1970-01-01
        • 2011-07-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多