Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ArticlesController
- <?php
- namespace App\Controller;
- class ArticlesController extends AppController {
- public function create() {
- $article = $this->Articles->newEntity();
- if ($this->request->is('post')) {
- $article = $this->Articles->patchEntity($article, $this->request->data(), [
- 'associated' => ['ArticleTypes']
- ]);
- dump($this->request->data);
- dump($article);
- }
- $this->set('article', $article);
- $this->set('articleTypes', $this->loadModel('ArticleTypes')->find('list')->toArray());
- }
- }
- ?>
- // ArticlesTable
- <?php
- namespace App\Model\Table;
- use Cake\ORM\Table;
- use Cake\Validation\Validator;
- use Cake\ORM\TableRegistry;
- class ArticlesTable extends Table {
- public function initialize(array $config) {
- parent::initialize($config);
- $this->addBehavior('Timestamp');
- $this->belongsTo('ArticleTypes', [
- 'foreignKey' => 'article_type_id',
- 'className' => 'ArticleTypes',
- 'propertyName' => 'article_type'
- ]);
- }
- }
- ?>
- // create.ctp
- <?= $this->Form->create($article) ?>
- <?= $this->Form->input('title') ?>
- <?= $this->Form->input('body', ['type' => 'textarea']) ?>
- <?= $this->Form->input('article_type.id', ['type' => 'select', 'options' => $articleTypes]) ?>
- <?= $this->Form->button('send') ?>
- <?= $this->Form->end() ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement