Advertisement
Guest User

Untitled

a guest
Dec 4th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. <?php
  2. // src/Model/Entity/Article.php
  3. namespace App\Model\Entity;
  4.  
  5. use Cake\ORM\Entity;
  6.  
  7. class Cat extends Entity
  8. {
  9.     protected $_accessible = [
  10.         '*' => true,
  11.     ];
  12.  
  13. }
  14.  
  15. <?php
  16. // src/Model/Entity/Article.php
  17. namespace App\Model\Entity;
  18.  
  19. use Cake\ORM\Entity;
  20.  
  21. class Dog extends Entity
  22. {
  23.     protected $_accessible = [
  24.         '*' => true,
  25.     ];
  26.  
  27. }
  28.  
  29. <?php
  30. // src/Model/Entity/Article.php
  31. namespace App\Model\Entity;
  32.  
  33. use Cake\ORM\Entity;
  34.  
  35. class Dog extends Entity
  36. {
  37.     protected $_accessible = [
  38.         '*' => true,
  39.     ];
  40.  
  41. }
  42.  
  43. <?php
  44. namespace App\Model\Table;
  45.  
  46. use App\Model\Entity\Cat;
  47. use Cake\ORM\Table;
  48. use Cake\ORM\Query;
  49. use Cake\ORM\RulesChecker;
  50. use Cake\ORM\Validation\Validator;
  51.  
  52.  
  53.  
  54. class CatsTable extends Table
  55. {
  56.     public function initialize(array $config)
  57.     {
  58.  
  59.         $this->addBehavior('Timestamp');
  60.  
  61.  
  62.         $this->hasMany('DogsCats',[
  63.             'foreignKey'=>'cat_id',
  64.         ]);
  65.     }
  66.  
  67.  
  68. }
  69.  
  70. <?php
  71.  
  72. namespace App\Model\Table;
  73.  
  74. use App\Model\Entity\Dog;
  75. use Cake\ORM\Table;
  76. use Cake\ORM\Query;
  77. use Cake\ORM\RulesChecker;
  78. use Cake\ORM\Validation\Validator;
  79.  
  80. class DogsTable extends Table
  81. {
  82.     public function initialize(array $config)
  83.     {
  84.         $this->addBehavior('Timestamp');
  85.  
  86.         $this->hasMany('DogsCats',[
  87.             'foreignKey'=>'dog_id'
  88.         ]);
  89.     }
  90.  
  91.  
  92. }
  93.  
  94. <?php
  95. namespace App\Model\Table;
  96.  
  97. use App\Model\Entity\DogsCat;
  98. use Cake\ORM\Table;
  99. use Cake\ORM\Query;
  100. use Cake\ORM\RulesChecker;
  101. use Cake\ORM\Validation\Validator;
  102.  
  103.  
  104.  
  105. class DogsCatsTable extends Table
  106. {
  107.     public function initialize(array $config)
  108.     {
  109.         $this->addBehavior('Timestamp');
  110.  
  111.  
  112.        $this->belongsTo('Dogs', [
  113.             'foreignKey' => 'id',
  114.             'joinType'=>'INNER'
  115.         ]);
  116.  
  117.         $this->belongsTo('Cats', [
  118.             'foreignKey' => 'id',
  119.             'joinType'=>'INNER'
  120.         ]);
  121.  
  122.  
  123.  
  124.     }
  125.  
  126.  
  127. }
  128.  
  129. <?php
  130.  
  131. namespace App\Controller;
  132. use App\Controller\AppController;
  133.  
  134. class DogsCatsController extends AppController
  135. {
  136.     public function initialize()
  137.     {
  138.         parent::initialize();
  139.  
  140.         $this->loadComponent('Paginator');
  141.         $this->loadComponent('Flash');
  142.     }
  143.  
  144.     public function index()
  145.     {
  146.        
  147.      $result = $this->DogsCats->find('all')->contain(['Dogs','Cats']);
  148.      $this->set('farms',$result);
  149.  
  150.    
  151.     }
  152.  
  153.     public function add()
  154.     {
  155.  
  156.     }
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement