【问题标题】:How i can fetch table posts_tags on CAKEPHP我如何在 CAKEPHP 上获取表 posts_tags
【发布时间】:2014-04-28 00:01:21
【问题描述】:

我在 MySQL“posts_tags”上有表,我想在控制器的 View 操作中获取表行,但我不知道如何?

【问题讨论】:

    标签: cakephp tags posts


    【解决方案1】:

    假设您已经为 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
    
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 2015-08-01
      • 2012-06-05
      • 2015-07-01
      • 2011-08-15
      • 2012-05-30
      • 2011-07-15
      • 2017-10-27
      • 1970-01-01
      相关资源
      最近更新 更多