Home > Backend Development > PHP Tutorial > PHP development framework Yii Framework tutorial (31) Zii component-DetailView example

PHP development framework Yii Framework tutorial (31) Zii component-DetailView example

黄舟
Release: 2023-03-05 09:16:01
Original
1452 people have browsed it

CDetailView displays detailed content for a Model. The Model to be displayed can be CModel or an associative array.

CDetailView determines the format in which the attributes of the Model need to be displayed by configuring attributes.

Each attribute can be configured using Name:Type:Label. Both Type and Label are optional.

"Name" attribute name.

"Label" Optional, the label name of the attribute. If not configured, the attribute name will be used as the label name.

"Type ” The type of the attribute, which determines the displayed formatter. The types that can be used include raw, text, ntext, html, date, time, datetime, boolean, number, email, image, url. etc., and text is used by default.

This example modifies the previous example Yii Framework Development Tutorial (30) Zii component-ListView example, and modifies the list item template _view.php of the display list so that the customer name changes from ordinary text to Link.

FirstName . ' ' . $data->LastName,
$this->createUrl('view',array('CustomerId'=>$data->CustomerId))); ?>

When you click on the customer's name, go to the link view.php, and set the incoming parameter CustomerId to the Customer's ID.
Create View.php and use the CDetailView component.

widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'FirstName',
'LastName',
'Company',
'Address',
'City',
'State',
'Country',
'PostalCode',
'Phone',
'Fax',
'Email',
array(
'name'=>'Employee',
'value'=>$model->employee->FirstName,
),
),
));
?>
Copy after login

Use the default format to display each field of Customer, the main Employee field. The Customer table defines SupportRepId as a foreign key reference to Employee, so modify the Customer class to define Relations, refer to the Yii Framework development tutorial ( 27) Database-Associated Active Record Example

public function relations()
{
return array(
'employee'=>array(self::BELONGS_TO,
'Employee', 'SupportRepId'),
);
}
Copy after login

The display results are as follows:

PHP development framework Yii Framework tutorial (31) Zii component-DetailView example


The above is the PHP development framework Yii Framework Tutorial (31) Zii component-DetailView example content, please pay attention to the PHP Chinese website (m.sbmmt.com) for more related content!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template