Advertisement
logratate

Untitled

May 18th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. // ArticlesController
  2. <?php
  3. namespace App\Controller;
  4.  
  5. class ArticlesController extends AppController {
  6.    
  7.     public function create() {
  8.         $article = $this->Articles->newEntity();
  9.        
  10.         if ($this->request->is('post')) {
  11.            
  12.             $article = $this->Articles->patchEntity($article, $this->request->data(), [
  13.                 'associated' => ['ArticleTypes']
  14.             ]);
  15.            
  16.             dump($this->request->data);
  17.             dump($article);
  18.            
  19.         }
  20.        
  21.         $this->set('article', $article);
  22.         $this->set('articleTypes', $this->loadModel('ArticleTypes')->find('list')->toArray());
  23.     }
  24.    
  25. }
  26. ?>
  27.  
  28. // ArticlesTable
  29. <?php
  30. namespace App\Model\Table;
  31.  
  32. use Cake\ORM\Table;
  33. use Cake\Validation\Validator;
  34. use Cake\ORM\TableRegistry;
  35.  
  36. class ArticlesTable extends Table {
  37.    
  38.     public function initialize(array $config) {
  39.         parent::initialize($config);
  40.        
  41.         $this->addBehavior('Timestamp');
  42.         $this->belongsTo('ArticleTypes', [
  43.             'foreignKey' => 'article_type_id',
  44.             'className' => 'ArticleTypes',
  45.             'propertyName' => 'article_type'
  46.         ]);
  47.        
  48.     }
  49.    
  50. }
  51. ?>
  52.  
  53. // create.ctp
  54. <?= $this->Form->create($article) ?>
  55. <?= $this->Form->input('title') ?>
  56. <?= $this->Form->input('body', ['type' => 'textarea']) ?>
  57. <?= $this->Form->input('article_type.id', ['type' => 'select', 'options' => $articleTypes]) ?>
  58. <?= $this->Form->button('send') ?>
  59. <?= $this->Form->end() ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement