PathFinder_Exception无法包含Model / Model / using setModel

时间:2012-05-01 01:19:59

标签: php user-interface frameworks atk4

我正在尝试使用http://agiletoolkit.org/doc/modeltable/reference中给出的示例手动从一个模型创建一个引用到另一个模型。我正在使用以下表格和模型:

人员表

  • id:主键
  • name:char
  • room_number:int
  • 电子邮件:char

用户表

  • id:主键
  • person_id:人员表(id)的外键
  • 密码:char

ATK4.2课程如下:

人物模型

class Model_Person extends Model_Table {
public $entity_code='person';

function init(){
    parent::init();
    $this->addField('name');
    $this->addField('roomnumber');
    $this->addField('email');
}
}

用户模型

'user'表包含密码字段。

class Model_User extends Model_Table {
public $entity_code='user';

function init(){
    parent::init();

    $field_ref = $this->add('Field_Reference', 'person_id');
    $field_ref->dereferenced_field = 'person_str';
    // add referenced Model
    $m = $this->add('Model_Person');
    $m->addField('name');
    // Link referenced model field name to this model field.
    $field_ref->setModel($m, 'name');


}
}

但是,我收到以下错误,其中Model_Person类使用错误的路径添加,Model / Model / Person.php

PathFinder_Exception

Unable to include Model/Model/Person.php

Additional information:

    type: php
    attempted_locations: Array ( [0] => /var/www/html/seqtrack/admin/lib/Model/Model/Person.php [1] => /var/www/html/seqtrack/atk4/lib/Model/Model/Person.php [2] => /var/www/html/seqtrack/admin/../lib/Model/Model/Person.php [3] => /var/www/html/seqtrack/atk4/../atk4-addons/mvc/Model/Model/Person.php [4] => /var/www/html/seqtrack/atk4/../atk4-addons/misc/lib/Model/Model/Person.php ) 

/var/www/html/seqtrack/atk4/lib/BaseException.php:38
Stack trace:
/var/www/html/seqtrack/atk4/lib/BaseException.php   :38     PathFinder_Exception    PathFinder_Exception->collectBasicData(Null, 1, 0)
/var/www/html/seqtrack/atk4/lib/PathFinder.php  :213    PathFinder_Exception    PathFinder_Exception->__construct("Unable to include Model/Model/Person.php")
/var/www/html/seqtrack/atk4/lib/PathFinder.php  :131    PathFinder_Exception    PathFinder_Exception->__construct("php", "Model/Model/Person.php", Array(5))
/var/www/html/seqtrack/atk4/lib/PathFinder.php  :195    test_pathfinder PathFinder->locate("php", "Model/Model/Person.php", "path")
/var/www/html/seqtrack/atk4/lib/AbstractObject.php  :159    test_pathfinder PathFinder->loadClass("Model_Model_Person")
/var/www/html/seqtrack/atk4/lib/Field/Reference.php :89     test_mgr_tabs_view_htmlelement_crud_model_user_person_id    Field_Reference->add("Model_Model_Person")
/   :   test_mgr_tabs_view_htmlelement_crud_model_user_person_id    Field_Reference->calculateSubQuery(Object(Model_User), Object(DB_dsql_mysql), Object(Field_Expression))
/var/www/html/seqtrack/atk4/lib/Field/Expression.php    :44         Loggercall_user_func(Array(2), Object(Model_User), Object(DB_dsql_mysql), Object(Field_Expression))
/var/www/html/seqtrack/atk4/lib/Model/Table.php :169    test_mgr_tabs_view_htmlelement_crud_model_user_person_str   Field_Expression->updateSelectQuery(Object(DB_dsql_mysql))
/var/www/html/seqtrack/atk4/lib/Model/Table.php :327    test_mgr_tabs_view_htmlelement_crud_model_user  Model_User->selectQuery()
/var/www/html/seqtrack/atk4/lib/CompleteLister.php  :104    test_mgr_tabs_view_htmlelement_crud_model_user  Model_User->rewind()
/var/www/html/seqtrack/atk4/lib/Grid/Basic.php  :175    test_mgr_tabs_view_htmlelement_crud_grid    Grid->renderRows()
/var/www/html/seqtrack/atk4/lib/CompleteLister.php  :118    test_mgr_tabs_view_htmlelement_crud_grid    Grid->renderRows()
/var/www/html/seqtrack/atk4/lib/Grid/Advanced.php   :152    test_mgr_tabs_view_htmlelement_crud_grid    Grid->render()
/var/www/html/seqtrack/atk4/lib/AbstractView.php    :214    test_mgr_tabs_view_htmlelement_crud_grid    Grid->render()
/var/www/html/seqtrack/atk4/lib/AbstractView.php    :205    test_mgr_tabs_view_htmlelement_crud_grid    Grid->recursiveRender()
/var/www/html/seqtrack/atk4/lib/AbstractView.php    :205    test_mgr_tabs_view_htmlelement_crud CRUD->recursiveRender()
/var/www/html/seqtrack/atk4/lib/AbstractView.php    :205    test_mgr_tabs_view_htmlelement  View_HtmlElement->recursiveRender()
/var/www/html/seqtrack/atk4/lib/AbstractView.php    :205    test_mgr_tabs   Tabs->recursiveRender()
/var/www/html/seqtrack/atk4/lib/AbstractView.php    :205    test_mgr    page_mgr->recursiveRender()
/var/www/html/seqtrack/atk4/lib/ApiWeb.php  :236    test    AdminFrontend->recursiveRender()
/var/www/html/seqtrack/atk4/lib/ApiFrontend.php :123    test    AdminFrontend->execute()
/var/www/html/seqtrack/atk4/lib/ApiWeb.php  :226    test    AdminFrontend->execute()
/var/www/html/seqtrack/admin/index.php  :8  test    AdminFrontend->main()

在ATK DVD示例网页上可以看到类似的问题:

http://example.agiletoolkit.org/examples/dvdrental/

PathFinder_Exception

Unable to include Model/Model/Customer.php

Additional information:

type: php
attempted_locations: Array ( [0] => /www/agiletoolkit.org/example/examples/dvdrental/lib/Model/Model/Customer.php [1] => /www/agiletoolkit.org/example/atk4/lib/Model/Model/Customer.php [2] => /www/agiletoolkit.org/example/atk4/../atk4-addons/mvc/Model/Model/Customer.php [3] => /www/agiletoolkit.org/example/atk4/../atk4-addons/misc/lib/Model/Model/Customer.php ) 

/www/agiletoolkit.org/example/atk4/lib/BaseException.php:38
Stack trace:
/www/agiletoolkit.org/example/atk4/lib/BaseException.php    :38     PathFinder_Exception    PathFinder_Exception->collectBasicData(Null, 1, 0)
/www/agiletoolkit.org/example/atk4/lib/PathFinder.php   :209    PathFinder_Exception    PathFinder_Exception->__construct("Unable to include Model/Model/Customer.php")
/www/agiletoolkit.org/example/atk4/lib/PathFinder.php   :134    PathFinder_Exception    PathFinder_Exception->__construct("php", "Model/Model/Customer.php", Array(4))
/www/agiletoolkit.org/example/atk4/lib/PathFinder.php   :195    Frontend_pathfinder PathFinder->locate("php", "Model/Model/Customer.php", "path")
/www/agiletoolkit.org/example/atk4/lib/AbstractObject.php   :158    Frontend_pathfinder PathFinder->loadClass("Model_Model_Customer")
/www/agiletoolkit.org/example/atk4/lib/AbstractController.php   :26     Frontend    Frontend->add("Model_Model_Customer")
/www/agiletoolkit.org/example/examples/dvdrental/lib/RentalAuth.php :5  Frontend_rentalauth RentalAuth->setModel("Model_Customer")
/www/agiletoolkit.org/example/atk4/lib/AbstractObject.php   :181    Frontend_rentalauth RentalAuth->init()
/www/agiletoolkit.org/example/examples/dvdrental/lib/Frontend.php   :21     Frontend    Frontend->add("RentalAuth")
/www/agiletoolkit.org/example/atk4/lib/ApiCLI.php   :48     Frontend    Frontend->init()
/www/agiletoolkit.org/example/atk4/lib/ApiWeb.php   :38     Frontend    Frontend->__construct(Null)
/www/agiletoolkit.org/example/examples/dvdrental/index.php  :3  Frontend    Frontend->__construct()

干杯。


更新

代码片段需要进入User类,所以它现在看起来像这样:

class Model_User extends Model_Table {
public $entity_code='user';

function init(){
    parent::init();

    $this->hasOne('Person');

    $field_ref = $this->getField('person')->rename('person_str');
    $this->getField('person_id')->dereferenced_field='person_str';

    // add referenced Model
    $m = $this->add('Model_Person');
    $m->addField('name');

    // Link referenced model field name to this model field.
    $field_ref->setModel($m, 'name');

}
}

生成的SQL是:

选择idperson_id,(从name person选择userperson_id = person。{{来自id

的1}})person_str

但是,下面的类也会生成相同的SQL statemetn。

user

所以我不太了解其余代码的功能和需求: $这 - > getfield命令( 'PERSON_ID') - > dereferenced_field = 'person_str';

class Model_User extends Model_Table {
public $entity_code='user';

function init(){
    parent::init();

    $this->hasOne('Person');

    $this->getField('person')->rename('person_str');

}
}

我希望我们能对此有进一步的解释,谢谢。

1 个答案:

答案 0 :(得分:0)

在你的人物模型中试试这个

$this->hasOne('Person');
$this->getField('person')->rename('person_str');
$this->getField('person_id')->dereferenced_field='person_str';

否则“setmodel”不能与预先创建的对象一起使用。