Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. //StoriesControlles
  2. public function index()
  3. {
  4.     $this->set('storie', $this->Stories->find('all'));
  5.  
  6.     $storie = $this->Stories->find('all')->contain(['Categories', 'Users']);
  7.     $this->set(compact('storie'));
  8. }
  9.  
  10. public function view($id = null)
  11. {
  12.     $storie = $this->Stories->get($id);
  13.     $this->set(compact('storie'));
  14.  
  15.     $storie = $this->Stories->get($id, ['contain' => ['Categories', 'Users']]);
  16.     $this->set(compact('storie'));
  17. }
  18.  
  19. // StoriesTable
  20. $this->table('stories');
  21. $this->belongsTo('Categories', [
  22.     'className' => 'categories',
  23.     'foreignKey' => 'categorie_id',
  24. ]);
  25. // Stories, action index.ctp
  26. <li><div class="text-info push-5-t"><strong>Categoria: <?= h($storie->categorie->name) ?></strong></div></li>
  27.  
  28. // Stories, action view.ctp
  29. <h6 class="label label-default">Categoria: <?= h($storie->categorie->name) ?></h6>
  30.  
  31. // CategoriesTable
  32. $this->table('categories');
  33. $this->hasMany('Stories', [
  34.     'className' => 'categories',
  35.     'bindingKey' => 'categorie_id',
  36. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement