English 中文(简体)
• 如何只取得有卡克普西图图像的产品
原标题:How to get only products with images in CakePhp
<?php
class Product extends AppModel {
    var $name =  Product ;

    //The Associations below have been created with all possible keys, those that are not needed can be removed

    var $belongsTo = array(
         Category  => array(
             className  =>  Category ,
             foreignKey  =>  category_id ,
             conditions  =>   ,
             fields  =>   ,
             order  =>   
        ),
         Brand 
    );


    var $hasOne = array(
         PhotoSmall  => array(
             className  =>  Photo ,
             foreignKey  =>  product_id ,
             dependent  => true,
             conditions  =>  PhotoSmall.tipo = "small" ,
             fields  =>   ,
             order  =>   ,
             limit  =>   ,
             offset  =>   ,
             exclusive  =>   ,
             finderQuery  =>   ,
             counterQuery  =>   
        ),
    );

    var $hasMany = array(
         PhotoBig  => array(
             className  =>  Photo ,
             foreignKey  =>  product_id ,
             dependent  => true,
             conditions  =>  PhotoBig.tipo = "big" ,
             fields  =>   ,
             order  =>  PhotoBig.order ,
             limit  =>   ,
             offset  =>   ,
             exclusive  =>   ,
             finderQuery  =>   ,
             counterQuery  =>   
        ),
         Rating  => array(
             className  =>  Rating ,
             foreignKey  =>  product_id ,
             dependent  => false,
             conditions  =>   ,
             fields  =>   ,
             order  =>   ,
             limit  =>   ,
             offset  =>   ,
             exclusive  =>   ,
             finderQuery  =>   ,
             counterQuery  =>   
        )
    );

我需要我的所有发现(除了行政区外)只检索有图像的产品。

在<代码>微量的情况下,我可以做<代码>。 照片Small.id IS NOT NUL,其条件是:CakePhp产生左加入,但不能找到至少要求在上加入的办法。 照片Big是因为Cake Php有两个问题要回去。

要求如下:我只能够展示带<条码>微量的产品,并展示一个至少有一个<条码>的微量度/代码>广域(除网站行政部分外)的系统,解决办法应当与CakePhp pagination合作。

我尝试了以下法典,但没有成功,它只是回报产品数据,而不是光线数据:

$this->Product->recursive = -1;
$conditions = array( Product.category_id => $cats);
$joins = array(
    array( table  =>  photos ,
         alias  =>  PhotoBig ,
         type  =>  INNER ,
         conditions  => array(
             Product.id = PhotoBig.product_id ,
        )
    ),
    array( table  =>  photos ,
         alias  =>  PhotoSmall ,
         type  =>  INNER ,
         conditions  => array(
             Product.id = PhotoBig.product_id ,
        )
    )
);
$this->paginate = array(
     limit  => 12,
     conditions  => $conditions,
     joins  => $joins,
);
问题回答

you need to additionally use contain - at least that worked for me (due to your recursive=-1):

 contain  => array( PhotoSmall ,  PhotoBig ),

the joins are only the setup configuration. without specifying your data you will only get the one model s data.

do you use the containable behavior? would be the easiest solution. if not, try to set recursive to 0 or 1.

PS:在条件范围内,你的第二个方面是错的(可能是那里的小型照片)。

首先,你重新造位到-1级,这应当只是向你们提供产品数据,而不管你发现什么。

为什么在类似产品模式的发现中,你不会这样做和条件:

    $this->Product->find( all , array( recursive  => 1,  conditions  => array(
    "NOT" => array( PhotoSmall.id  => NULL,  PhotoBig.id  => NULL))));

注:休庭至少需要一次,因为你需要相关数据。





相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

Using DISTINCT in a CakePHP find function

I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list. Choose the filter ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

Prevent controller from trying to autoload model

I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call ...

热门标签