Advertisement
Guest User

Untitled

a guest
Mar 12th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.98 KB | None | 0 0
  1. //howto controller
  2. public function actionCreate()
  3.     {
  4.         Yii::import('ext.multimodelform.MultiModelForm');
  5.         $step = new Step;
  6.         $model = new Howto;
  7.         $validatedSteps = array(); //ensure an empty array
  8.  
  9.         $this->performAjaxValidation( $model, 'howto-form' );
  10.         if ( isset ( $_POST['Howto'] ) )
  11.         {
  12.             $model->attributes = $_POST['Howto'];
  13.             $masterValues = array ('howto_id'=>$model->id);
  14.              if ( MultiModelForm::save($step,$validatedSteps,$deleteSteps,$masterValues) &&
  15.             $model->save()
  16.            )
  17.                 $this->redirect( array( 'view' , 'id'=>$model->id ) );
  18.         }
  19.        
  20.  
  21.         $this->render('create',array(
  22.             'model'=>$model,
  23.             'step'=>$step,
  24.             'validatedSteps'=>$validatedSteps
  25.         ));
  26.     }
  27.  
  28.     /**
  29.      * Updates a particular model.
  30.      * If update is successful, the browser will be redirected to the 'view' page.
  31.      */
  32.      
  33.    
  34.     public function actionUpdate($id)
  35.     {
  36.          Yii::import('ext.multimodelform.MultiModelForm');
  37.         $model = $this->loadModel($id);
  38.         $step = new Step;
  39.         $validatedSteps = array(); //ensure an empty array
  40.         $this->performAjaxValidation( $model, 'howto-form' );
  41.    
  42.        
  43.         if ( isset ( $_POST['Howto'] ) )
  44.         {
  45.             $model->attributes = $_POST['Howto'];
  46.             $masterValues = array ('howto_id'=>$model->id);
  47.              if ( MultiModelForm::save($step,$validatedSteps,$deleteSteps,$masterValues) &&
  48.             $model->save()
  49.            )
  50.                 $this->redirect( array( 'view' , 'id'=>$model->id ) );
  51.         }
  52.    
  53.        
  54.         $this->render('update',array(
  55.             'model'=>$model,
  56.             'step'=>$step,
  57.             'validatedSteps'=>$validatedSteps
  58.         ));
  59.     }
  60.  
  61. //howto/create
  62.  
  63. <h1>Share some knowledge!</h1>
  64.  
  65.  
  66. <?php echo $this->renderPartial('_form',
  67.         array( 'model'=>$model,'step'=>$step,'validatedSteps'=>$validatedSteps ) ); ?>
  68.  
  69. //howto/update
  70.  
  71. <?php
  72. $this->breadcrumbs=array(
  73.     $model->title=>$model->url,
  74.     'Update',
  75. );
  76. ?>
  77.  
  78. <h1>Update <i><?php echo CHtml::encode( $model->title ); ?></i></h1>
  79.  
  80. <?php echo $this->renderPartial('_form',
  81.         array( 'model'=>$model,'step'=>$step,'validatedSteps'=>$validatedSteps ) ); ?>
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. // howto/_form
  90. <div class="form">
  91.  
  92. <?php
  93.     $form = $this->beginWidget('BootActiveForm',
  94.     array(
  95.         'id'=>'howto-form',
  96.         'enableAjaxValidation'=>true,
  97.         'enableClientValidation'=>true,
  98.          'clientOptions' =>
  99.          array(
  100.           'validateOnSubmit'=>true,
  101.           'validateOnChange'=>true,
  102.           'validateOnType'=>true,
  103.              ),
  104.         'htmlOptions'=>array( 'class'=>'well' ),
  105.         ) );
  106.  ?>
  107.  
  108.     <?php     echo $form->errorSummary(array_merge(array($model),$validatedSteps));?>
  109.  
  110.     <div class="row">
  111.         <?php echo $form->labelEx($model,'title'); ?>
  112.         <?php echo $form->textField($model,'title',array('size'=>80,'maxlength'=>128)); ?>
  113.         <?php echo $form->error($model,'title'); ?>
  114.     </div>
  115.  
  116.     <div class="row">
  117.     <?php echo $form->error($model,'content'); ?>
  118.     <?php echo $form->textArea($model,'content',array('style'=>'display:none'));?>
  119.     <?php
  120.         $this->widget('application.extensions.elrte.elRTE',
  121.         array(
  122.             'selector'=>'#Howto_content',
  123.             'userid'=>Yii::app()->user->id,
  124.         ));
  125.     ?>
  126.        
  127.     </div>
  128.  
  129.     <div class="row">
  130.         <?php echo $form->labelEx($model,'tags'); ?>
  131.         <?php $this->widget('CAutoComplete', array(
  132.             'model'=>$model,
  133.             'attribute'=>'tags',
  134.             'url'=>array('suggestTags'),
  135.             'multiple'=>true,
  136.             'htmlOptions'=>array('size'=>50),
  137.         )); ?>
  138.         <p class="hint">Please separate different tags with commas.</p>
  139.         <?php echo $form->error($model,'tags'); ?>
  140.     </div>
  141.  
  142.     <div class="row">
  143.         <?php echo $form->labelEx($model,'status'); ?>
  144.         <?php echo $form->dropDownList($model,'status',Lookup::items('HowtoStatus')); ?>
  145.         <?php echo $form->error($model,'status'); ?>
  146.     </div>
  147.    
  148.     <a onClick="$('#stepContainer').show();" rel=".id_step_copy" href="#" id="id_step">Manage Steps</a>
  149.    
  150.     <div id="stepContainer" style="display:none">
  151. <?php
  152.     $stepFormConfig = array(
  153.       'elements'=>array(
  154.         'title'=>array(
  155.             'type'=>'text',
  156.             'maxlength'=>40,
  157.         ),
  158.         'text'=>array(
  159.             'type'=>'textarea',
  160.             'maxlength'=>6000,
  161.             'class'=>'eltre',
  162.         ),
  163.        
  164.     ));
  165.  
  166.     $this->widget('ext.multimodelform.MultiModelForm',
  167.     array(
  168.         'id' => 'id_step', //the unique widget id
  169.         'formConfig' => $stepFormConfig, //the form configuration array
  170.         'model' => $step, //instance of the form model
  171.         'jsAfterClone'=>'$("#editorPlaceholder").load("/howto/eltre")',
  172.         'tableView'=>false,
  173.         'addItemText'=>'',
  174.         //if submitted not empty from the controller,
  175.         //the form will be rendered with validation errors
  176.         'validatedItems' => $validatedSteps,
  177.  
  178.         //array of member instances loaded from db
  179.         'data' => $step->findAll('howto_id=:howtoId', array(':howtoId'=>$model->id)),
  180.     ));
  181. ?>
  182.  
  183.     <div id="editorPlaceholder"></div>
  184.        
  185.    
  186.     <div class="row buttons">
  187.         <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',
  188.             array( 'class'=>'btn btn-primary' ) ); ?>
  189.     </div>
  190.  
  191. <?php $this->endWidget(); ?>
  192.         </div><!-- stepContainer-->
  193.     </div><!-- form -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement