YiiFramework development tutorial (31) Zii component-DetailView example
CDetailView displays details for a Model. The Model to be displayed can be a CModel or an associated array.
CDetailView configures attributes to determine the format in which the attributes of the Model must be displayed.
You can use Name: Type: Label to configure each attribute. Both Type and Label are optional.
"Name" attribute Name.
"Label" can be selected. the Label name of the attribute. if not configured, the attribute name is used as the Label name.
The Type of the "Type" attribute. The formatter format is determined by the Type. available types include raw, text, ntext, html, date, time, datetime, boolean, number, email, image, url.. text is used by default.
In this example, modify the Yii Framework Development Tutorial (30) Zii component-ListView example, and modify the list item template _ view. php of the display list to change the customer name from plain text to Link.
Double-click all code
12 |
FirstName. ''. $ data-> LastName, $ this-> createUrl ('View', array ('mermerid' => $ data-> CustomerId);?> |
When you click the Customer name, go to the link view. php and set the CustomerId parameter to the Customer ID.
Create View. php and use the CDetailView component
Double-click all code
12345678910111213141516171819202122232425 |
Widget ('zii. widgets. CDetailView ', array ('data' => $ model, 'bubuckets' => array ('firstname', 'lastname', 'Company', 'address', 'city ', 'state', 'country', 'postalcode', 'phone', 'fax', 'Email ', array ('name' => 'employe ', 'value' => $ model-> employee-> FirstName,),);?> |
The default format is used to display each field of the Customer, which is the main Employee field. the Customer table defines SupportRepId as the foreign key reference. Therefore, the Customer-like definition Relations is modified, see Yii Framework Development Tutorial (27) database-associated Active Record example
Double-click all code
1234567 |
Publicfunctionrelations () {returnarray ('employee' => array (self: BELONGS_TO, 'employee', 'orortrepid '),);} |
The result is as follows:
Download this example