[英]Create a dashboard in Yii Framework
我是yii
新手。 我正在Yii
做一個小應用程序。 假設我有一些表,例如product, sales, discount, customer,
現在我已經為這些表完成了所有的Models和Controllers(crud)。 現在,當管理員想要輸入一種新產品時,他正在輸入
http://localhost/application/index.php?r=product
。 同樣,他必須輸入折扣才能進入折扣部分。 現在,我想像儀表板一樣在一個應用程序中呈現所有模塊。 管理員可以直接從單個頁面進行更改的地方。 所以有人可以告訴我如何解決這個問題。 任何幫助和建議都是非常可取的。
編輯我已經瀏覽了一些鏈接,但是我沒有在那找到任何文檔。
首先,您應該考慮應該在儀表板上顯示的內容,您已經選擇了一些實體。 從這些實體可能會有不同的顯示項目標准:
sales
會顯示最高的銷售額? 現在,您應該選擇何時允許對這些項目進行某些操作。
publish
, update
orders
現在,要完成此操作,您將必須定義幾個數據提供程序,設置幾個列表視圖,並將所有這些都放入DashboardController
。 沒有! 從Yii慣例到MVC,通常應該有: fat模型 , 該控制器和明智的看法。
考慮到上述因素,您應該為每種數據類型創建小部件。 窗口小部件應該是“獨立的”,就像您的儀表板的“模型”一樣。 應該包含實體類型所需的所有邏輯,並且不要求任何配置(也用於自動創建)。
對於儀表板小部件,您還應該為此創建一些基類,因此儀表板小部件將看起來一致:具有一些布局。
為此,一個很好的開始是CPortLet
它已經定義了某種東西,例如儀表板小部件,帶有標題和圍繞其內容的div
。
這是一些從Portlet開始的示例:
class ProductDashboard extends CPortlet // Or intermediate class, ie. DashboardItem
{
protected $_products = array();
public function init()
{
$this->_products = new CActiveDataProvider('Product', array(
'criteria'=>array(
'with'=>array('...'),
'order'=>'t.sort_order ASC',
'condition'=>'...',
'together'=>true,
),
));;
$this->title= 'Newset producs';
parent::init();
}
protected function renderContent()
{
$this->render('productDashboard');
}
}
在portlet視圖中, views/productDashboard.php
只是放置listview:
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_productView',
'enablePagination'=>true,
));
在_productView
放置有關產品的所有信息:
<h4><?= CHtml::encode($data->name); ?></h4>
<p><?= CHtml::encode($data->description); ?></p>
<p>
<?= CHtml::link('Update', array('/product/update', 'id' => $data->id)); ?>
<?= CHtml::link('View', array('/product/view', 'id' => $data->id)); ?>
... More actions ...
</p>
最后,在儀表板索引視圖中放置這些portlet:
$this->widget('path.to.ProductDashboard');
$this->widget('path.to.SalesDashboard');
....
或以某種自動化方式:
// Possibly user defined only etc.
$widgets = array('ProductDashboard', 'SalesDashboard', ...);
foreach($widgets as $name)
$this->widget($name)
聽起來您想實現一個菜單。 假設您至少已經完成了Ignat B.提到的“ 創建第一個Yii應用程序” ,則可以閱讀CMenu類文檔以了解它們,並且您layout.php
修改將在protected\\views
中的layout.php
文件中進行。
如果它是您要查找的菜單列表,則可以嘗試以下擴展: http : //www.yiiframework.com/extension/emetrotile
您所需要做的就是按照源代碼中的說明進行操作,然后在要加載的位置調用它,類似於以下內容:
$this->widget('ext.emetrotile.EMetroTile', array(
'Tiles'=>array(
array('title'=>'Test Title', 'tiles'=>array(
array('content'=>array('test1-a','test1-b'), 'liveTileOptions'=>array('data-speed'=>750, 'data-delay'=>3000,'data-stack'=>true)),
array('content'=>'test2', 'position'=>'bottom'),
array('content'=>'test4', 'position'=>'bottom'),
array('content'=>'Blog', 'style'=>'vertical', 'url'=>'http://blog.expressthisout.com'),
array('content'=>'test3', 'style'=>'horizontal'),
array('content'=>'test5', 'position'=>'bottom'),
array('content'=>'test6', 'position'=>'top'),
))
)
));
正如Syakur Rahman所說,emetrotile是創建儀表板的良好擴展。 我用它創建了一個漂亮的3 x 2菜單,每個菜單的前面都有一個圖像,背面是文本,它們依次依次翻轉。 它具有非常酷的效果,但確實具有Windows感覺。
德魯·格林(Drew Green)編寫的原始js似乎一直都在改進,請參閱http://www.drewgreenwell.com/projects/metrojs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.