我有一个ActiveForm
,不想通过$_POST
发送数据。所有数据都是$_GET
发送的,即使我这样做了:
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\models\Lang;
use backend\models\View;
use backend\models\Page;
use yii\helpers\ArrayHelper;
use kartik\select2\Select2;
use jlorente\remainingcharacters\RemainingCharacters;
use backend\components\OutData;
/* @var $this yii\web\View */
/* @var $model backend\models\Page */
/* @var $form yii\widgets\ActiveForm */
$_SESSION['KCFINDER'] = array(
'disabled' => false,
'uploadURL' => "/media",
'uploadDir' => Yii::getAlias('@frontend/web') . "/media/",
);
?>
<div class="panel-wrapper collapse in" aria-expanded="true">
<div class="panel-body">
<form action="#">
<div class="form-body">
<h3 class="box-title">Информация</h3>
<hr>
<?php $form = ActiveForm::begin([
'id' => 'update-form',
'action' => \yii\helpers\Url::to(['page/create']),
'method' => "post",
]); ?>
<?php $languages = Lang::find()->all(); ?>
<ul class="nav nav-tabs">
<?php
foreach ($languages as $key => $language) {
if ($language->default == 1) {
echo '<li class="active"><a data-toggle="tab" href="#' . $key . '">' . $language->name . '</a></li>';
} else {
echo '<li><a data-toggle="tab" href="#' . $key . '">' . $language->name . '</a></li>';
}
}
?>
</ul>
<div class="tab-content">
<?php
foreach ($languages as $key => $language) {
if ($language->default != 1) {
echo '<div id="' . $key . '" class="tab-pane fade">';
echo '<div class="row">';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'title_' . $language->url)->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'url_' . $language->url)->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '</div>';
echo '<div class="row">';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'meta_title_' . $language->url)->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'meta_description_' . $language->url)->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '<div col-xs-12><div class="form-group">';
$textContent = 'content_' . $language->url;
if (!$model->isNewRecord) {
$model->$textContent = OutData::showTXT($model->$textContent);
}
echo $form->field($model, 'content_' . $language->url)->textarea();
echo "<script>
CKEDITOR.replace( 'Page[content_$language->url]' );
</script>";
echo '</div></div>';
echo '</div>';
} else {
echo '<div id="' . $key . '" class="tab-pane fade in active">';
echo '<div class="row">';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'title')->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'url')->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '</div>';
echo '<div class="row">';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'meta_title')->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '<div class="col-sm-6"><div class="form-group">';
echo $form->field($model, 'meta_description')->widget(RemainingCharacters::classname(), [
'type' => RemainingCharacters::INPUT_TEXT,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'myCounter',
'invalidClass' => 'error'
],
'options' => [
'class' => 'form-control',
'maxlength' => true,
]
]);
echo '</div></div>';
echo '<div class="col-xs-12"><div class="form-group">';
if (!$model->isNewRecord) {
$model->content = OutData::showTXT($model->content);
}
echo $form->field($model, 'content')->textarea();
echo "<script>
CKEDITOR.replace( 'Page[content]' );
</script>";
echo '</div></div>';
echo '</div>';
}
echo '</div>';
}
?>
</div>
<div class="row">
<div class="col-sm-6">
<?php
$mas[0] = Yii::t('app', 'Главна страница');
$mas['----------------'] = ArrayHelper::map(Page::find()->where('id_in=0 and is_cat=1')->all(), 'id', 'title');
?>
<?=
$form->field($model, 'id_in')->widget(Select2::classname(), [
'model' => $model,
'attribute' => 'id_in',
'data' => $mas,
'options' => [
'placeholder' => Yii::t('app', 'Select a type ...'),
],
'pluginOptions' => [
'allowClear' => true
],
])
?>
</div>
<div class="col-sm-6">
<?php
if ($model->isNewRecord) {
echo $form->field($model, 'view_id')->hiddenInput(['value' => 12])->label(false);
} else {
echo $form->field($model, 'view_id')->hiddenInput(['value' => $model->view_id])->label(false);
}
?>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<?= $form->field($model, 'sort')->textInput() ?>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<?= $form->field($model, 'active')->hiddenInput(['value' => ($model->active) ? $model->active : 2])->label(false) ?>
<?= Html::activeLabel($model, 'active', ['class' => 'dblock flLeft mr5 pt5']); ?>
<label class="switch switch-custom block dblock flLeft">
<input type="checkbox" value="1" id="active_<?= $model->id ?>"class="legend-switch" <?= ($model->active == 1) ? 'checked="checked"' : '' ?> onchange="changeHiddenField('page-active', 'active_<?= $model->id ?>');"></input>
<label data-off="<?= Yii::t('app', 'Не'); ?>" data-on="<?= Yii::t('app', 'Да') ?>" for="active_<?= $model->id ?>"></label>
</label>
</div>
<div class="col-sm-3">
<?= $form->field($model, 'in_main_menu')->hiddenInput(['value' => ($model->in_main_menu) ? $model->in_main_menu : 2])->label(false) ?>
<?= Html::activeLabel($model, 'in_main_menu', ['class' => 'dblock flLeft mr5 pt5']); ?>
<label class="switch switch-custom block dblock flLeft">
<input type="checkbox" value="1" id="in_main_menu_<?= $model->id ?>"class="legend-switch" <?= ($model->in_main_menu == 1) ? 'checked="checked"' : '' ?> onchange="changeHiddenField('page-in_main_menu', 'in_main_menu_<?= $model->id ?>');"></input>
<label data-off="<?= Yii::t('app', 'Не'); ?>" data-on="<?= Yii::t('app', 'Да') ?>" for="in_main_menu_<?= $model->id ?>"></label>
</label>
</div>
<div class="col-sm-3">
<?= $form->field($model, 'in_side_menu')->hiddenInput(['value' => ($model->in_side_menu) ? $model->in_side_menu : 2])->label(false) ?>
<?= Html::activeLabel($model, 'in_side_menu', ['class' => 'dblock flLeft mr5 pt5']); ?>
<label class="switch switch-custom block dblock flLeft">
<input type="checkbox" value="1" id="in_side_menu_<?= $model->id ?>"class="legend-switch" <?= ($model->in_side_menu == 1) ? 'checked="checked"' : '' ?> onchange="changeHiddenField('page-in_side_menu', 'in_side_menu_<?= $model->id ?>');"></input>
<label data-off="<?= Yii::t('app', 'Не'); ?>" data-on="<?= Yii::t('app', 'Да') ?>" for="in_side_menu_<?= $model->id ?>"></label>
</label>
</div>
<?= $form->field($model, 'is_cat')->hiddenInput(['value' => ($model->is_cat) ? $model->is_cat : 0])->label(false) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'app.Create') : Yii::t('app', 'app.Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<script>
$('#w0').on('beforeValidate', function (event, messages, deferreds) {
for (var instanceName in CKEDITOR.instances) {
CKEDITOR.instances[instanceName].updateElement();
}
return true;
});
</script>
<script>
function selectView(view_id) {
if (view_id == 9) {
$('#page-is_cat').val(1);
} else {
$('#page-is_cat').val(0);
}
}
</script>
这是我的语法吗?什么会导致这种问题? 这是我的控制者:
public function actionCreate() {
$model = new Page();
$model->user_id = Yii::$app->user->identity->id;
/*var_dump($_POST);die;*/
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model = $this->findModel($model->id, true);
$languages = Lang::find()->all();
foreach ($languages as $language) {
if ($language->default != 1) {
$title = 'title_' . $language->url;
// $url = MakeURL::parseUrl($model->$title, $model->id);
$urlName = 'url_' . $language->url;
$model->$urlName = MakeURL::parseUrlGoogle($model->$urlName, $model->id);
$content = 'content_' . $language->url;
$var = Yii::$app->OutData->sanitize($model->$content);
$model->$content = $var;
} else {
// $url = MakeURL::parseUrl($model->title, $model->id);
$model->url = MakeURL::parseUrlGoogle($model->url, $model->id);
$model->content = Yii::$app->OutData->sanitize($model->content);
}
}
$model->old_link = 2;
$model->save();
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
已编辑全视图。