私はphpアクティブレコードを試しています。これは素晴らしいORMですが、行き詰まっています。
Google、ブログ、phpactiverecord のドキュメント、および statckoverflow を数日間調べましたが、この問題に対する適切な解決策を見つけることができませんでした。
基本的な CRUD (挿入、フェッチ、変更、および削除) 操作を実行できますが、静的な $validates_uniqueness_of フィルターを使用してオブジェクト プロパティを検証するとすぐに、
致命的なエラー: キャッチされない例外 'ActiveRecord\DatabaseException'
メッセージ付き
メッセージ「SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test_ar.models' doesn't exist」を含む例外「PDOException」が C:\wamp\www\test_AR\AR\lib\Connection.php に表示される325
これが私が完全に使用したコードです。
<?php
$path_to_AR = "AR/";
include $path_to_AR . "activerecord.php";
ActiveRecord\Config::initialize(function($cfg) {
$cfg->set_model_directory('model');
$cfg->set_connections(
array(
'development' => 'mysql://root:asdf@localhost/test_ar',
'test' => 'mysql://username:password@localhost/test_database_name',
'production' => 'mysql://username:password@localhost/production_database_name'
)
);
});
/*
class user extends ActiveRecord\Model
{
static $validates_presence_of = array(array('username', 'message' => 'Please supply a username')); //this works just fine
static $validates_uniqueness_of = array(array('username'));//this line causes the PDO exception
}
*/
$user = new user();
user::create((array('username'=>'mike','password'=>'test','created'=>time())));
$user::create(array('username'=>'mike')); //cannot even reach this line because of the exeption
私が試した/見た参照
https://github.com/kla/php-activerecord/issues/274 (何が起こっているのかよくわかりませんが)
http://www.phpactiverecord.org/projects/main/wiki/Validations#validates_uniqueness_of
http://blog.felho.hu/what-is-new-in-php-53-part-2-late-static-binding.html
他の多くと同様に。
プラットフォームと PHP のバージョン
私は php 5.3.4 を使用しており、ナイトリー ビルド (2013 年 5 月 8 日) を使用しています。これを修正する方法についてアドバイスをお願いします。