Yii2: Custom Form Name

In my _form.php, I am trying to change the default form title.

Actually, what I want to change in the text in bold - Create a city before Create a custom city

To achieve this, I try to use this code, but I get the error: - Could not find the message source for the category "City".

example1

<?php
$this->title = Yii::t('City','Custom City');
?>

example 2- I do not get any errors, but the name of the form also does not change.

<?php
$this->title = 'Custom City';
?>

I put under all the code _form.php:

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;   

/* @var $this yii\web\View */
/* @var $model app\models\City */
/* @var $form yii\widgets\ActiveForm */

$this->title = ('Custom City');

$this->params['breadcrumbs'][] = $this->title;
?>



<div class="row">
    <div class="col-lg-3">

    </div>
    <div class="col-lg-5 col-lg-offset-1">
    <div class="city-form">

        <?php $form = ActiveForm::begin(); ?>

        <?= $form->field($model, 'state_id')->DropDownList(ArrayHelper::map(State::find()->all(), 'id', 'state_name' ),
    [ 'prompt' => 'Please Select' ])?>

        <?= $form->field($model, 'city_name')->textInput() ?>

        <div class="form-group">
            <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        </div>

        <?php ActiveForm::end(); ?>

    </div>

City form view

+4
source share
1 answer

You can set or change the _form.php header from create.php.

This means that you can find in your create.php file

$this->title = 'Create City';

which can be changed to anything.

+3
source

All Articles