Monday 8 June 2015

Yii 1.1: get current model name.

in Yii, if you are adding custom fields to forms, you need to add model name to the input fields like this:

<input name="ModelName[fieldname]"/>

here, you have access to $model, but, from this, you cannot get the model name.

Simply use PHP's get_class() method to do this:

$ModelName = get_class($model);

So, the final code should be:

<input name="<?php echo $ModelName;?>[fieldname]"/>

No comments:

Post a Comment

Parenting tips to inculcate learning habits in your kid

Parenting tips to inculcate learning habits in your kid Tip #1) Children do not learn things, they emitate. So, try to do things by yours...