はじめてのCakePHPアプリでハマった箇所の対応方法

第5回 CakePHPで作るToDoアプリ(1)|gihyo.jp … 技術評論社
を参考にCakaPHPでアプリを作ってみましたが、古い記事だったので結構はまりました。
対応した内容をメモしておきます。

・環境

Ubuntu11.04-server, Apache2.2.17, PHP5.3.5

・app/tmpディレクトリの権限エラーが出たので、権限を追加しました。
$ chmod -R 777 app/tmp
・以下の警告が出たので、core.phpのSecurity.salt, Security.cipherSeedを変更しました。

app/config/core.php

Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE/cake/libs/debugger.php, line 694]
・以下のエラーが出たので、mod_rewriteの設定をしました。(これが一番ハマった...)
URL rewriting is not properly configured on your server.

1. Help me configure it
2. I don't / can't use URL rewriting

mod_rewriteの設定

$ sudo a2enmod rewrite
Enabling module rewrite.
Run '/etc/init.d/apache2 restart' to activate new configuration!
$ sudo /etc/init.d/apache2 restart

※ 私の場合、mod_rewriteの設定は有効になっていたのですが、なぜかうまく動かない…。
原因はDLしたCakePHP.zipを解凍して、プロジェクトディレクトリにコピーしたのですが、
その際に「.htaccess」がコピーできていませんでした。 orz
.htaccess」を作成してあげたら、無事動きましたー。

SQL Errorが発生、findAllメソッドは非推奨になったのでfindメソッドを使いました。
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'findAll' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684]

app/controllers/tasks_controllers.php

class TasksController extends AppController {
    var $name = 'Tasks';
    var $uses = array('Task');
    
    function index() {
	// $this->set('tasks', $this->Task->findAll(null, null, 'Task.created ASC'));
        $this->set('tasks', $this->Task->find('all', array('order'=>'Task.created ASC')));
    }
}
・Viewの日本語が文字化けしたので、DB設定でコメントアウトされていた「'encoding' => 'utf8'」

を有効にしました。

app/config/database.php

	var $default = array(
		'driver' => 'mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'user',
		'password' => 'password',
		'database' => 'todo',
		'prefix' => '',
		'encoding' => 'utf8',
	);
これでようやく、一覧画面が表示できるようになりました。

f:id:t-taira:20110921122643p:image