Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //howto controller
- public function actionCreate()
- {
- Yii::import('ext.multimodelform.MultiModelForm');
- $step = new Step;
- $model = new Howto;
- $validatedSteps = array(); //ensure an empty array
- $this->performAjaxValidation( $model, 'howto-form' );
- if ( isset ( $_POST['Howto'] ) )
- {
- $model->attributes = $_POST['Howto'];
- $masterValues = array ('howto_id'=>$model->id);
- if ( MultiModelForm::save($step,$validatedSteps,$deleteSteps,$masterValues) &&
- $model->save()
- )
- $this->redirect( array( 'view' , 'id'=>$model->id ) );
- }
- $this->render('create',array(
- 'model'=>$model,
- 'step'=>$step,
- 'validatedSteps'=>$validatedSteps
- ));
- }
- /**
- * Updates a particular model.
- * If update is successful, the browser will be redirected to the 'view' page.
- */
- public function actionUpdate($id)
- {
- Yii::import('ext.multimodelform.MultiModelForm');
- $model = $this->loadModel($id);
- $step = new Step;
- $validatedSteps = array(); //ensure an empty array
- $this->performAjaxValidation( $model, 'howto-form' );
- if ( isset ( $_POST['Howto'] ) )
- {
- $model->attributes = $_POST['Howto'];
- $masterValues = array ('howto_id'=>$model->id);
- if ( MultiModelForm::save($step,$validatedSteps,$deleteSteps,$masterValues) &&
- $model->save()
- )
- $this->redirect( array( 'view' , 'id'=>$model->id ) );
- }
- $this->render('update',array(
- 'model'=>$model,
- 'step'=>$step,
- 'validatedSteps'=>$validatedSteps
- ));
- }
- //howto/create
- <h1>Share some knowledge!</h1>
- <?php echo $this->renderPartial('_form',
- array( 'model'=>$model,'step'=>$step,'validatedSteps'=>$validatedSteps ) ); ?>
- //howto/update
- <?php
- $this->breadcrumbs=array(
- $model->title=>$model->url,
- 'Update',
- );
- ?>
- <h1>Update <i><?php echo CHtml::encode( $model->title ); ?></i></h1>
- <?php echo $this->renderPartial('_form',
- array( 'model'=>$model,'step'=>$step,'validatedSteps'=>$validatedSteps ) ); ?>
- // howto/_form
- <div class="form">
- <?php
- $form = $this->beginWidget('BootActiveForm',
- array(
- 'id'=>'howto-form',
- 'enableAjaxValidation'=>true,
- 'enableClientValidation'=>true,
- 'clientOptions' =>
- array(
- 'validateOnSubmit'=>true,
- 'validateOnChange'=>true,
- 'validateOnType'=>true,
- ),
- 'htmlOptions'=>array( 'class'=>'well' ),
- ) );
- ?>
- <?php echo $form->errorSummary(array_merge(array($model),$validatedSteps));?>
- <div class="row">
- <?php echo $form->labelEx($model,'title'); ?>
- <?php echo $form->textField($model,'title',array('size'=>80,'maxlength'=>128)); ?>
- <?php echo $form->error($model,'title'); ?>
- </div>
- <div class="row">
- <?php echo $form->error($model,'content'); ?>
- <?php echo $form->textArea($model,'content',array('style'=>'display:none'));?>
- <?php
- $this->widget('application.extensions.elrte.elRTE',
- array(
- 'selector'=>'#Howto_content',
- 'userid'=>Yii::app()->user->id,
- ));
- ?>
- </div>
- <div class="row">
- <?php echo $form->labelEx($model,'tags'); ?>
- <?php $this->widget('CAutoComplete', array(
- 'model'=>$model,
- 'attribute'=>'tags',
- 'url'=>array('suggestTags'),
- 'multiple'=>true,
- 'htmlOptions'=>array('size'=>50),
- )); ?>
- <p class="hint">Please separate different tags with commas.</p>
- <?php echo $form->error($model,'tags'); ?>
- </div>
- <div class="row">
- <?php echo $form->labelEx($model,'status'); ?>
- <?php echo $form->dropDownList($model,'status',Lookup::items('HowtoStatus')); ?>
- <?php echo $form->error($model,'status'); ?>
- </div>
- <a onClick="$('#stepContainer').show();" rel=".id_step_copy" href="#" id="id_step">Manage Steps</a>
- <div id="stepContainer" style="display:none">
- <?php
- $stepFormConfig = array(
- 'elements'=>array(
- 'title'=>array(
- 'type'=>'text',
- 'maxlength'=>40,
- ),
- 'text'=>array(
- 'type'=>'textarea',
- 'maxlength'=>6000,
- 'class'=>'eltre',
- ),
- ));
- $this->widget('ext.multimodelform.MultiModelForm',
- array(
- 'id' => 'id_step', //the unique widget id
- 'formConfig' => $stepFormConfig, //the form configuration array
- 'model' => $step, //instance of the form model
- 'jsAfterClone'=>'$("#editorPlaceholder").load("/howto/eltre")',
- 'tableView'=>false,
- 'addItemText'=>'',
- //if submitted not empty from the controller,
- //the form will be rendered with validation errors
- 'validatedItems' => $validatedSteps,
- //array of member instances loaded from db
- 'data' => $step->findAll('howto_id=:howtoId', array(':howtoId'=>$model->id)),
- ));
- ?>
- <div id="editorPlaceholder"></div>
- <div class="row buttons">
- <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',
- array( 'class'=>'btn btn-primary' ) ); ?>
- </div>
- <?php $this->endWidget(); ?>
- </div><!-- stepContainer-->
- </div><!-- form -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement