如何做到這一點?我的例子...
文件夾結構:
Application (Your App Folder)
|
|
protected (Folder)
|
|
widget (Folder)
|
|
views (Folder)
| |
| blog.php (PHP View file)
|
Blog.php (PHP Class file)
blog.php的保護/小工具下/下保護/小工具/視圖
<?php
class Blog extends CWidget
{
public $dataProvider;
public function init()
{
// this method is called by CController::beginWidget()
}
public function run()
{
$dataSet=$this->dataProvider->getData();
$this->render('blog', array('dataSet'=>$dataSet));
}
}
?>
blog.php的/
<!-- Your View as you want. Example: -->
<table>
<tr>
<th>Blog Name</th>
<th>Description</th>
</tr>
<?php foreach ($dataSet as $data): ?>
<tr>
<td><?= $data->name; ?></td>
<td><?= $data->description; ?></td>
</tr>
<?php endforeach; ?>
</table>
How t o使用此小工具
<?php
$dataProvider=new CActiveDataProvider('YourBlogModel'); //It has to come from controller
$this->widget('application.widget.Blog', array('dataProvider' => $dataProvider));
?>