Friday, 15 May 2015

php - Add condition to join table in pagination query (CakePHP 2.0.4) -


All images are default category images and other category related image descriptions are created in that table. This list will display the following questions in 2 categories (Pagesgun) of categories.

Select `Class`````````````````````````````````````````````````````````````````````` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` ` `` `` , `` `` ``` `` `` `` `` `` `` `` `` `'`' `` `` `` ` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` ` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` 'Improved', `Image`. `` Image`` in the form of `image` from` images`, where `image`. ' Category_ID `IN (60, 17, 9, 33, 71, 18, 73, 30, 58, 54, 3, 44, 64, 66, 67, 11, 53, 16, 23, 68) Pre>

But in fact, the second should be like the query:

  choose `image```````````````````````````` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` ` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `Image``` Image` as `Image` in category_ID (60, 17, 9, 33, 71, 18, 73, 30, 58, 54, 3, 44, 64, 66, 67, 11, 53, 16, 23, 6, 8)  

may be

image . In the default = 1 WHERE section.

My Controller is FPP Index Action:

  Public Function Index () {$ this- & gt; Category-> Recursive = 1; $ This- & gt; Category & gt; Behaviors-> Gave ('keep'); $ This-> gtaginate = array ("contain" => array ("image")); $ Search = ""; If (isset ($ this-> params ['name'] ['search'])) {$ search = str_replace ("% 20", "", $ this-> parameter ['name'] ['search'] ); $ Circumstances = array ('OR' = & gt; array (array ('named as category' = '>'% '. $' Search '%))); $ This- & gt; Set ('categories', $ this- & gt; paginated ($ terms)); } And {$ this- & gt; Set ('categories', $ this- & gt; paginated ()); } $ Success = $ this- & gt; Session-> Read ('success'); $ This- & gt; Set (compact ('search', 'success')); }  

and in the category of my category:

  many = array in public $ ('panel' = & gt; array (...) , 'Image' = & gt; array ('className' = & gt; 'image', 'foreign key' = & gt; 'category_id', 'dependent' = & gt; false, 'conditions' = & gt; array ('Image.default' = & gt; '1'), 'Field' = & gt; '', 'order' => "',' limit '= & gt;", "' offset '= & Gt; '', 'Exclusive' =>, '', 'Finder' =>; '', 'countertype' =>););  

Therefore, I have to filter the joining table images. Set the default set to '1'

Change this row in your categories controller:

  $ this-> paginate = array ("contain" => array ("image")); From  

to:

  $ this-> paginate = array ("contain" => array ("Image.default = 1"));  

More info here:


No comments:

Post a Comment