cakephp3 find all where code example

Example 1: cannot get all value from the contain cakephp

// on each model MUST HAVE THIS ROW for containable the model
	public $actsAs = array('Containable');

Ex:
<?php
App::uses('BuildingAppModel', 'Building.Model');
/**
 * CreditType Model
 *
 * @property CompanyCredit $CompanyCredit
 * @property CreditTypeLanguage $CreditTypeLanguage
 */
class CreditType extends BuildingAppModel {

	public $actsAs = array('Containable');
///   ...
}
 ?>

// First: need to check model for the relationship is it correct?
// next: MUST ADD THIS ROW for show all contain

'BuildingFacility' => array(
  'fields' => array(
    'BuildingFacility.id',		// MUST ADD THIS ROW for show all contain
  ),
  'BuildingFacilityLanguage' => array(
    'conditions' => array(
      'BuildingFacilityLanguage.alias' => $this->lang18,
    ),
  ),
  'BuildingPost' => array(
    'fields' => array(
      'BuildingPost.*',
    ),
    'BuildingPostLanguage' => array(
      'conditions' => array(
        'BuildingPostLanguage.alias' => $this->lang18,
      ),
    ),
  ),
),

Example 2: single or cakephp

// ------------------------------------
// ------------ one OR --------------
// ------------------------------------
$conditions = array(
    'OR' => array(
        array( 'MemberRole.school_id' 	=> array()),
        array( 'MemberRole.role_id' 	=> $role),
    );
);

// ------------------------------------
// ------------ multiple OR --------------
// ------------------------------------
 'OR' => array(
   array(
     'MemberRole.school_id' 	=> array(),
     'MemberRole.role_id' 	=> $role,
   ),
   array(
     'MemberRole.school_id' 	=> array(),
     'MemberRole.role_id' 	=>  Environment::read('role.register'),
   ),
   array(
     'MemberRole.school_id' 	=> $school_id,
     'MemberRole.role_id' 	=> Environment::read('role.register'),
   ),
   array(
     'MemberRole.school_id' 	=> $school_id,
     'MemberRole.role_id' 	=> $role
   )
 )

Tags:

Php Example