Script & CSS

2008年6月11日 星期三

在 PowerDesigner 設定 auto_increment 屬性

在 PowerDesigner 所產生的 MySQL 語法,若要新增 auto_increment 屬性,則可以在資料表編輯畫面左方(圖1紅色框選處)連點滑鼠左鍵,即可進入欄位編輯畫面(圖2),再鉤選右下角的 identify 後,產生的 MySQL 語法就會有 auto_increment 屬性。


圖1 資料表編輯


圖2 欄位編輯

2008年4月29日 星期二

(Model::validates) Parameter usage is deprecated

CakePHP 1.2 在使用 Model 的驗證(validate)功能時,會出現如下的警告訊息

Warning (512): (Model::validates) Parameter usage is deprecated, use Model::set() to update your fields first [CORE\cake\libs\model\model.php, line 2018]


可是我查詢1.2版的線上文件後發現我並沒有寫錯,我的語法如下所示
if ($this->MyModel->validates($this->data)) {
//code...
}

後來經由 google 查詢的結果發現1.2版的寫法必需改為
if ($this->MyModel->create($this->data) && $this->MyModel->validates()) { 
//code...
}

2008年4月10日 星期四

CakePHP 1.2 與 UTF8

CakePHP 1.2 在使用 MySQL 作為資料庫時,若資料庫格式為 UTF8 ,將會無法正確的讀/寫資料,必須將 config/database.php中的內容修改,如下所示:

class DATABASE_CONFIG {
    var $default = array(
        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'user',
        'password' => 'password',
        'database' => 'db',
        'prefix' => '',
        'encoding' => 'UTF8' // 加入這行
    );
} 

 

修改完成之後即可正確的存取資料庫內容。

2008年3月18日 星期二

xml_http_request 與 Rails2

在練習 Agile Web Development with Rails 2/e 第 13.4 節的應用程式整合測試時,AJAX 驗證測試程式一直無法成功通過,程式碼如下
xml_http_request "/store/add_to_cart" , :id => ruby_book.id

經過查詢 Rais2 的 API 文件之後,發現原來是 xml_http_request 的參數已經做了變更,詳細的參數與說明如下所示(節錄於 Rails2 API 文件)

xml_http_request(request_method, path, parameters = nil, headers = nil)

Performs an XMLHttpRequest request with the given parameters, mirroring a request from the Prototype library.

The request_method is :get, :post, :put, :delete or :head; the parameters are nil, a hash, or a url-encoded or multipart string; the headers are a hash. Keys are automatically upcased and prefixed with ‘HTTP_’ if not already.
This method is also aliased as xhr

看完文件後可發現 Rails 1.x 與 Rails 2.x 參數的差異為 request_method 這個參數,所以只要將第一個參數補上去,書上的範例即可成功通過測試,程式碼如下
xml_http_request :post, "/store/add_to_cart" , :id => ruby_book.id

2008年2月16日 星期六

No :secret given to the #protect_from_forgery call 錯誤的解決方法

Rails 2.0 開啟 db based session 時,程式執行會出現下列錯誤訊息

No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).

若要解決此問題,必須將 app\controllers\application.rb中的
protect_from_forgery # :secret => 'your_secret_id'
修改為
protect_from_forgery :secret => 'your_secret_id'

即可將此問題排除。

2007年10月25日 星期四

在遠端桌面傳送Ctrl+Alt+Del指令

在遠端桌面的操控畫面,按下 Ctrl+Alt+End 即可送出 Ctrl+Alt+Del 指令。