2011年5月15日 #php #php #cakephp #xml

CakephpでXMLを配列に変換するのはとても簡単です。
下記のファンクションを使えば一発でできます。

uses('Xml');
$xml = new Xml("/path/to/xml");
$xml_array = Set::reverse($xml);

MacportでPHPをインストールし、CakePHPを動かしたら「Strict Standards」エラーが出ました。
当時のエラー本文は残ってませんので、Googleで検索したエラー本文を貼り付けます。パス以外は同じのはずです。

Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/basics.php on line 279
Strict Standards: Redefining already defined constructor for class Object in /Applications/MAMP/htdocs/xxxx/cake/libs/object.php on line 65
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/object.php on line 92
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/inflector.php on line 65
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/configure.php on line 96
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/configure.php on line 154
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/cache.php on line 71
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/cache.php on line 157
Strict Standards: Non-static method Configure::getInstance() should not be called statically in /Applications/MAMP/htdocs/xxxx/cake/bootstrap.php on li

解決方法

これはCakePHPの問題ではなく、PHPのerror_reportingの設定問題だそうです。
php.iniを開いてerror_reportingで検索します。
値をE_ALLに変更すれば解決です。

ちなみにMacportでPHPをインストールしたときのphp.iniパスは/opt/local/etc/php5/php.iniになります。

参考リンク

http://oldblog.awpny.com/2007/12/mamp-php5-cakephp-and-strict-standards/

2011年2月 3日 #php #php #cakephp #model #orm
$this->Ingredient->save($newData);
$newIngredientId = $this->Ingredient->id;    // OK
// id以外のフィールドはダメ
$this->Ingredient->name;    // NG
$this->Ingredient->category;    // NG

登録/更新には関係なく。
公式マニュアルでは:

一度保存が完了してしまうと、オブジェクトの ID をモデルオブジェクトの $id プロパティで取得することができます。特に新しいオブジェクトを生成した場合に便利です。

と書いてありますが、id以外のフィールド情報は持ってないようです。
欲しければ$this->dataから取れます。