Yii $form->textfield, how to set a default value?

后端 未结 7 1451
心在旅途
心在旅途 2021-02-12 11:32

So I am fiddling with the Yii Framework and in one of the views, specifically the create form, I am trying to give one of my textfields a default value. Therefore when I go onto

7条回答
  •  逝去的感伤
    2021-02-12 11:51

    I believe the MVC way to do this is to place your default value either in your Model:

    class MyModel extends \yii\db\ActiveRecord
    {
        public $teamlead = 'my default value';
        ....
    }
    

    Or in your controller:

    class MyModelController extends Controller
    {
        public function actionCreate()
        {
            $model = new MyModel ();
            $model->teamlead = 'my default value';
            ...
        }
    }
    

提交回复
热议问题