2015-09-28 83 views
0

當我嘗試在我的形式來驗證身份,獨特的文件出現問題,不能正常工作,但是當我創建脈衝按鍵,獨特的Valide形式,但有另一種看法..我的形式是一種動態形式。 這是我的動態形式:獨特的驗證不起作用

<?php 
use yii\helpers\Html; 
use yii\widgets\ActiveForm; 
use yii\helpers\ArrayHelper; 
use frontend\models\Oficinas; 
use frontend\models\Departamento; 
use yii\helpers\Url; 
/* @var $this yii\web\View */ 
/* @var $model frontend\models\Solicitante */ 
/* @var $form yii\widgets\ActiveForm */ 
?> 
<div class="solicitante-form"> 
    <?php $form = ActiveForm::begin(); ?> 
    <?= $form->field($model, 'id_oficina')->dropDownList(    ArrayHelper::map(Oficinas::find()->all(),'id_oficina','descripcion_oficina'), 
       [ 
        'prompt'=>'Seleccione la Oficina ...', 
        'onchange'=>' 
         $.post("'.Url::toRoute('departamento/lists?id=').'"+$(this).val(), function(data) { 
          $("select#solicitante-id_departamento").html(data); 
        });' 
     ]); ?>     

    <?= $form->field($model, 'id_departamento')->dropDownList(
       ArrayHelper::map(Departamento::find()->all(), 'id_departamento','descripcion_depar'), 
       [ 
        'prompt'=>'Seleccione el Departamento ...', 
     ]); ?> 
    <?= $form->field($model, 'cedula_solicitante')->textInput() ?> 
    <?= $form->field($model, 'nombre')->textInput(['maxlength' => true]) ?> 
    <?= $form->field($model, 'apellido')->textInput(['maxlength' => true]) ?> 
    <?= $form->field($model, 'telefonos')->textInput() ?> 
    <?= $form->field($model, 'correo_electronico')->textInput(['maxlength' => true]) ?> 
    <div class="form-group"> 
     <?= Html::submitButton($model->isNewRecord ? 'Crear' : 'Modificar', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 
    </div> 
    <?php ActiveForm::end(); ?> 
</div> 

和我的控制器:

<?php 
namespace frontend\controllers; 
use Yii; 
use frontend\models\Solicitante; 
use frontend\models\SolicitanteSearch; 
use frontend\models\GruposTecnicos; 
use frontend\models\Model; 
use yii\web\Controller; 
use yii\web\NotFoundHttpException; 
use yii\filters\VerbFilter; 
use yii\filters\AccessControl; 
use common\models\HtmlHelpers; 
use frontend\models\SolicitudServicio; 
use frontend\models\SolicitudServicioSearch; 
use yii\helpers\ArrayHelper; 
use common\components\AccessRule; 
use common\models\User; 
/** 
* SolicitanteController implements the CRUD actions for Solicitante model. 
*/ 
class SolicitanteController extends Controller 
{ 
    public function behaviors() 
    { 
     return [   
     'verbs' => [ 
        'class' => VerbFilter::className(), 
        'actions' => [ 
         'delete' => ['post'], 
        ], 
       ], 
       'access' => [ 
        'class' => AccessControl::className(), 
        // We will override the default rule config with the new AccessRule class 
        'ruleConfig' => [ 
         'class' => AccessRule::className(), 
        ], 
        'only' => ['index','create', 'update', 'delete','view','prueba'], 
        'rules' => [ 
         [ 
          'actions' => ['index','create','view','update','delete','prueba'], 
          'allow' => true, 
          // Allow users, moderators and admins to create 
          'roles' => [               
           User::ROLE_ADMINISTRADOR, 
           User::ROLE_SUPER_USUARIO, 
          ], 
         ], 
          [ 
          'actions' => ['index','create','view','update','prueba'], 
          'allow' => true, 
          // Allow users, moderators and admins to create 
          'roles' => [               
           User::ROLE_OPERADOR, 
          ], 
         ], 
          [ 
          'actions' => ['index'], 
          'allow' => true, 
          // Allow users, moderators and admins to create 
          'roles' => [               
           User::ROLE_COORDINADOR, 
           User::ROLE_TECNICO, 
          ], 
         ],            
         ],           
      'denyCallback' => function ($rule,$user) { 
        //Yii::$app->user->loginRequired(); 
        Yii::$app->session->setFlash('error', 'DISCULPE USTED NO TIENE LOS PERMISOS NECESARIOS PARA REALIZAR ESTA ACCION.'); 
        return $this->goHome(); 
      }, 
       ],     
     ]; 
    } 

    /** 
    * Lists all Solicitante models. 
    * @return mixed 
    */ 
    public function actionIndex() 
    { 
     $rol=Yii::$app->user->identity->role; 
     if($rol=='ADMINISTRADOR' || $rol=='SUPER_USUARIO' || $rol=='OPERADOR'){ 

     $searchModel = new SolicitanteSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 
     return $this->render('index', [ 
      'searchModel' => $searchModel, 
      'dataProvider' => $dataProvider, 
     ]);  
     }else{ 
     $searchModel = new SolicitanteSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 
     return $this->render('index2', [ 
      'searchModel' => $searchModel, 
      'dataProvider' => $dataProvider, 
      ]); 
      } 
    } 
    public function actionView($id) 
    { 
     return $this->render('view', [ 
      'model' => $this->findModel($id), 
     ]); 
    } 
    public function actionCreate() 
    { 
     $model = new Solicitante(); 
     if ($model->load(Yii::$app->request->post()) && $model->save()) {   
      // var_dump(Yii::$app->request->post());die; 

      return $this->redirect(['view', 'id' => $model->id_solicitante]); 
     } else { 
      return $this->renderAjax('create', [ 
       'model' => $model, 
      ]); 
     } 
    } 

在這裏的錯誤1的IMG:
http://s8.postimg.org/71totbzat/Error1.jpg

錯誤2: http://s14.postimg.org/jiftd3z7l/Error2.jpg

回答

0

你只是改變你的形式提交按鈕名稱

<?= Html::submitButton($model->isNewRecord ? 'Crear' : 'Modificar', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 

<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Modificar', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 

而且還需要在控制器actionCreate()樣變..

return $this->renderAjax('create', [ 
      'model' => $model, 
]); 

return $this->render('create', [ 
      'model' => $model, 
]); 
+0

泰......問題是在渲染..但現在如果我更改渲染renderAjax看看發生了什麼.. http://s14.post img.org/d378gr8y9/Error_Img.jpg ......但RenderAjax。 :HTTP://s18.postimg.org/p3nkwwag9/Error_Img2.jpg ...我想要的視圖顯示的內容我沒有RenderAjax(唯一確認)..但是當我按下按鈕創建沒有Ajax的形式動態顯示我..形式更多菜單..你知道你知道什麼,可能是什麼錯誤? –