顯示具有 Yii Framework 標籤的文章。 顯示所有文章
顯示具有 Yii Framework 標籤的文章。 顯示所有文章

2013年2月15日 星期五

Yii 安裝 Bootstrap

安裝方法:
http://www.cniska.net/yii-bootstrap/setup.html

Github 版的 Yii Bootstrap 可以從這邊取得:
https://github.com/joujiahe/yii-bootstrap

注意: 需將 webapp/protected/extensions/bootstrap/theme/* 下的檔案複製到
webapp/themes/bootstrap/ 

Yii 使用偽靜態網址

在 webapp 下新增一個 .htaccess 檔,並將以下內容複製貼上:
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

修改 webapp/protected/config/main.php 設定檔來啟用 urlManager:
		// uncomment the following to enable URLs in path-format
		'urlManager'=>array(
			'urlFormat'=>'path',
			'showScriptName'=>false,
			'urlSuffix'=>'.html',
			'rules'=>array(
				'<controller:\w+>/<id:\d+>'=>'<controller>/view',
				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
			),
		),
這樣就可以將 index.php 藏起來並偽裝成 .html 的網址了。

2013年2月7日 星期四

Yii 抽象資料庫欄位類型的支援



Yii Migration 支援多種抽象欄位類型,如下所示:
  • pk: an auto-incremental primary key type, will be converted into "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
  • string: string type, will be converted into "varchar(255)"
  • text: a long string type, will be converted into "text"
  • integer: integer type, will be converted into "int(11)"
  • boolean: boolean type, will be converted into "tinyint(1)"
  • float: float number type, will be converted into "float"
  • decimal: decimal number type, will be converted into "decimal"
  • datetime: datetime type, will be converted into "datetime"
  • timestamp: timestamp type, will be converted into "timestamp"
  • time: time type, will be converted into "time"
  • date: date type, will be converted into "date"
  • binary: binary data type, will be converted into "blob"


2013年1月28日 星期一

繼承 Yii Framework 中的 AR 類別

關聯式資料庫並不支援繼承,但是,我們可以藉由繼承 AR 的方式來產生子類別繼承。什麼時候會需要繼承 AR 呢?最常見的情況應該是使用者分角色的時候,

例如:網站的使用者,區分為管理員、一般和進階使用者。不管哪一種角色都使用同一個資料表,並藉由繼承 User AR 的方式來產生各自的 AR。

Yii 官方維基有一篇介紹文章,使用 Car AR 來繼承產生 Sport Car 和 Family Car。寫得簡單明瞭,可以參考看看:
http://www.yiiframework.com/wiki/198/single-table-inheritance/