zoukankan      html  css  js  c++  java
  • 一次典型的查询

        public function product($media_ad_id = 0, $product_id = 0)
        {
            $this->MediaAd->id = $media_ad_id;
            $media_ad          = $this->MediaAd->read();
            if (!$media_ad) {
                $this->redirect(array(
                    'action' => 'nofound'
                ));
            }
        //这段代码用于验证用户操作
    $this->loadModel('MerchantProduct'); $this->loadModel('MerchantProductCategory'); $this->loadModel('MerchantProductPicture');
        //载入模型
    $this->MerchantProduct->recursive = -1;
      //关闭关联关系
    $product = $this->MerchantProduct->find('first', array( 'fields' => array( 'MerchantProduct.id', 'MerchantProduct.details', 'MerchantProduct.product_name', 'MerchantProduct.sell_price', 'MerchantProductCategory.id', 'MerchantProductCategory.name' ),
    // 需要的字段 'joins' => array( array( 'table' => 'merchants', 'alias' => 'Merchant', 'type' => 'inner', 'conditions' => array( 'Merchant.id = MerchantProduct.merchant_id' ) ),
    //关联 array( 'table' => 'merchant_product_categories', 'alias' => 'MerchantProductCategory', 'type' => 'inner', 'conditions' => array( 'MerchantProductCategory.id = MerchantProduct.cate_id' ) ) ), 'conditions' => array( 'MerchantProduct.id' => $product_id, 'MerchantProduct.active=1', 'Merchant.user_id' => $media_ad['MediaAd']['user_id'] )
    //条件 ));
    if (!$product) { $this->redirect(array( 'action' => 'nofound' )); } // 图片 $pic = $this->MerchantProductPicture->find('list', array( 'conditions' => array( 'MerchantProductPicture.product_id' => $product_id ) ));
    //单独获取这部分数据也是可以的哈、
    $this->set(compact('product', 'pic', 'media_ad_id', 'media_ad'));
    //输出到页面 }
  • 相关阅读:
    Django之admin
    Django之CSRF(跨站请求伪造)
    Django之Cookie
    Django之Session
    Django|第一部
    简单的udp消息收发
    .net core里使用ado.net访问sqlserver数据库
    CentOS8中安装SQLServer
    CentOS里配置.net core运行环境(含后台运行,附ssh长连接)
    发布"dotNet core"到CentOS8
  • 原文地址:https://www.cnblogs.com/linksgo2011/p/3011689.html
Copyright © 2011-2022 走看看