public function executeFormWidget(dmWebRequest $request) { $form = new ArticleForm(); if ($request->hasParameter($form->getName()) && $form->bindAndValid($request)) { $form->save(); $this->redirectBack(); } $this->forms['Article'] = $form; }
public function configure() { parent::configure(); $this->embedI18n(array('en', 'fr')); $authorForm = new AuthorForm($this->object->Author); unset($authorForm['id']); $this->embedForm('Author', $authorForm); unset($this['author_id']); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = new ArticleForm('view', $id); if (isset($_POST['ArticleForm'])) { $model->attributes = $_POST['ArticleForm']; $model->postItem->attributes = $_POST['PostItem']; $model->article->attributes = $_POST['Article']; $fileUpload = CUploadedFile::getInstance($model->article, 'article_image'); Yii::log(CVarDumper::dumpAsString($fileUpload)); if ($fileUpload !== null) { $model->article->removeImage(); $model->article->article_image = $fileUpload; } if ($model->validate() && $model->save()) { if ($fileUpload !== null) { $model->article->article_image->saveAs(Yii::app()->basePath . '/../files/images/articles/' . $model->article->article_image . "_" . $model->article->getPrimaryKey()); } $this->redirect(array('view', 'id' => $model->article->post_item_id)); } } $this->render('update', array('model' => $model)); }
$form = new DefaultValuesForm($author); $t->is($form->getDefault('name'), 'Jacques Doe', '->__construct() uses object value as a default for existing objects'); $author->delete(); // ->embedRelation() $t->diag('->embedRelation()'); class myArticleForm extends ArticleForm { } $table = Doctrine::getTable('Author'); $form = new AuthorForm($table->create(array('Articles' => array(array('title' => 'Article 1'), array('title' => 'Article 2'), array('title' => 'Article 3'))))); $form->embedRelation('Articles'); $embeddedForms = $form->getEmbeddedForms(); $t->ok(isset($form['Articles']), '->embedRelation() embeds forms'); $t->is(count($embeddedForms['Articles']), 3, '->embedRelation() embeds one form for each related object'); $form->embedRelation('Articles', 'myArticleForm', array(array('test' => true))); $embeddedForms = $form->getEmbeddedForms(); $moreEmbeddedForms = $embeddedForms['Articles']->getEmbeddedForms(); $t->isa_ok($moreEmbeddedForms[0], 'myArticleForm', '->embedRelation() accepts a form class argument'); $t->ok($moreEmbeddedForms[0]->getOption('test'), '->embedRelation() accepts a form arguments argument'); $form = new AuthorForm($table->create(array('Articles' => array(array('title' => 'Article 1'), array('title' => 'Article 2'))))); $form->embedRelation('Articles as author_articles'); $t->is(isset($form['author_articles']), true, '->embedRelation() embeds using an alias'); $t->is(count($form['author_articles']), 2, '->embedRelation() embeds one form for each related object using an alias'); $form = new AuthorForm($table->create(array('Articles' => array(array('title' => 'Article 1'), array('title' => 'Article 2'))))); $form->embedRelation('Articles AS author_articles'); $t->is(isset($form['author_articles']), true, '->embedRelation() embeds using an alias with a case insensitive separator'); $form = new ArticleForm(Doctrine::getTable('Article')->create(array('Author' => array('name' => 'John Doe')))); $form->embedRelation('Author'); $t->is(isset($form['Author']), true, '->embedRelation() embeds a ONE type relation'); $t->is(isset($form['Author']['name']), true, '->embedRelation() embeds a ONE type relation'); $t->is($form['Author']['name']->getValue(), 'John Doe', '->embedRelation() uses values from the related object');
protected function setupInheritance() { parent::setupInheritance(); $this->widgetSchema->setNameFormat('blog_article[%s]'); }
public function updateDefaultsFromObject() { parent::updateDefaultsFromObject(); }