Yii framework forum

I have been to many forums but this. You need some assistance but none to assist.

What kind of assistance do you need?

I have created a table category. It has Id, name, created_by, created_at entries. when i want to create the category I am supposed to fill the created_by and created_at. How can the form pick automatically the created_by which is the current user logged in and created_at the current time when i save the form.


Hello, for getting ID of currently logged in user you can call Yii::$app->user->id

And for current time you can use PHP function, for example:

$dt = new DateTime();
$dt->format(‘Y-m-d H:i:s’);

You can set these values as default values for input fields for attributes created_at and created_by. If you want to remain these field invisible to user make them with class Html::activeHiddenInput() Or you can assign these values elsewhere - in Controller action or Model beforeValidate() for example.

More info:

Thanks for the assistance! @kubove
Let me do it…