当我尝试在我的表单中验证身份证明文件是唯一的,但是当我按下脉冲创建按钮时,问题就出现了,表格中的唯一视词有另一种视图......我的形式是动态的形式。 这是我的动态表单:
<?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
答案 0 :(得分: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,
]);