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

后端 未结 7 786
孤独总比滥情好
孤独总比滥情好 2021-02-12 10:55

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 12:00

    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';
            ...
        }
    }
    
    0 讨论(0)
提交回复
热议问题