I need to have comments/hints for some fields in my Form. My idea is to describe it in model, just like attributeLabels. How can I do it?
And then it would be ideal, if the Gii Model (and Crud) generator would take it directly from mysql column’s comment
So I see two questions here:
Displaying Hints from Model
Here’s a slightly modified version of the default
login.phpfile generated byYiicLet’s move that password hint into the model by adding a
attributeHints()method and agetHint()method to theLoginForm.phpmodel.As you can see, we;ve moved the hint text from the view into the model and added a way to access it.
Now, back in
login.php, let’s add the hint tag based on data from the model.So now we’ve changed the hardcoded hint into a generated element populated with data from the model.
Now, moving on to the second question.
Getting hints from mySQL comments
Unforunately, I am not fammiliar enough with Gii to know how to automatically generate the hints from mySQL comments. However, getting the mySQL comment data into the model is fairly easy.
To do this we can use the following mySQL query
So let’s add the comment to the password field
And let’s add the code to fetch it into our
attributeHints()method.We now have two ways to set comments, through mySQL comments or through hard coded statements.
Let’s update our
login.phpfile quick to include hints of both types.And that’s it!
Now our login page will look like this, with a username hint from the model and a password hint from the mySQL comment.