Selected Category: CakePHP (3)

View Mode: Post List Post Summary

底下是我用來升級新版的 CakePHP 的作法:

  1. 解壓縮新版的 CakePHP 壓縮包
  2. 刪除解壓出來的所有 .htaccess
    • <解壓目錄>\.htaccess
    • <解壓目錄>\app\.htaccess
    • <解壓目錄>\app\webroot\.htaccess
  3. 更名以下檔案
    • <解壓目錄>\app\config\bootstrap.php => bootstrap.php.default
    • <解壓目錄>\app\config\core.php => core.php.default
    • <解壓目錄>\app\config\inflections.php => inflections.php.default
    • <解壓目錄>\app\config\routes.php => routes.php.default
  4. 將解壓出來的檔案複製到程式目錄中

 


Posted by HACGIS at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(32)

我在使用 Auth 這個 Component 時,由於很多地方都會使用到 User 這個 Model 來實現一些功能,所以我在 app_controller.php 裡面於 __construct 時將一個 User 物件 new 出來,並將其設為 AppController 的屬性來共用。

問題發生在 user/add 的 action 上面,當執行 $this->User->save($this->data) 時,總是會改寫到登入 User 的資料,而非新增一筆 User 的資料。
後來我發現,$this->User 的 id 屬性變成登入 User 的 id(正常的狀況是,這個 id 屬性應為 false)。
所以我檢查 app_controller.php 使用到 User 的地方,發現只要在 beforeFilter 這個方法內,另外 new 一個 User 物件出來代替使用 AppController 的 User 屬性即可解決這個問題。

Posted by HACGIS at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(168)

方法其實很簡單,在 Controller 裡面的 action function 裡面設定 $this->data 這個值即可。

add:
$this->data = $this->Model->create();

Posted by HACGIS at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(139)