ATK4 model not found when moving to online

感情迁移 提交于 2019-11-29 17:38:40
 Class 'model_TaskType' not found in 

you should always use exact capitalization.

if you have Model_TaskType, it should be Model_TaskType when added to CRUD.

also this place:

$this->addField('tasktype_id')->refModel('model_TaskType')->mandatory(true);

should be:

$this->addField('tasktype_id')->refModel('Model_TaskType')->mandatory(true);

On widows, file name capitalization does not make a difference, where as in linux it does.

in my experience with ATK4 (v4.1.3) this error is more likely a case-sensitivity and folder search declaration problem.

as the ATK4 PathFinder is the one responsible for loading all the classes, when you add() an object, like, Model_UserAccess it looks for different locations particularly: Model/UserAccess.php it then include() the file and then instantiates the class Model_UserAccess inside it, something like return new Model_UserAccess().

PathFinder changes all instances of underscores _ to / and traverse the locations accordingly.

therefore, a declaration something like this:

class Model_UserAccess extends Model_Table

and adding it:

$m = $this->add('Model_UserAccess');

searches and loads two files (not in particular order), 1st from: /Model/Table.php and 2nd from: /Model/UserAccess.php

once you are comfortable with this folder separation concept, developing in ATK4 will be much much easier.

i myself have a /lib/Model/ and /lib/Form/ and even a /lib/Form/Field/ since i am also redefining up to the field level. The latter would look something like:

class Form_Field_GraduatedSlider extends Form_Field

OK, seems a bit strange but this is what i found.

I have a model called Task which extends Table.

class Model_Task extends Model_Table {
public $entity_code='vscrum_task';
    public $table_alias='tk';

function init(){
  parent::init();
  $this->addField('id')->system(true)->visible(false);
  $this->addField('story_id')->system(true)->visible(false);
  $this->addField('backlog_ref')->system(true)->visible(false);

  $this->addField('status')->defaultValue('I')->visible(false);
  $this->addField('task_desc')->mandatory(true)->visible(true);

      $this->addField('member_id')->mandatory(true)->refModel('model_Member');

      // join colour
      $this->addRelatedEntity('ty','vscrum_tasktype','tasktype_id','left');

      //tasktype
      $this->addField('tasktype_id')->refModel('model_TaskType')->mandatory(true);
 }

I have a model called ScrumwallTask which extends Task

class Model_ScrumwallTask extends Model_Task {

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

  $this->addField('status')->defaultValue('I')->system(true);
      $this->addField('colour_desc')->datatype('text')->calculated(true);
      $this->addField('status')->visible(true);

    }

function calculate_colour_desc(){
        return $this->api->db->dsql()
            ->table('vscrum_colour')
            ->where('id=ty.colour_id')
            ->field('colour_desc')
            ->select();
    }
}

ScrumwallTask calls parent::init so i assumed it would get all the fields added to Task

I got rid of the error by duplicating the addField for tasktype_id into ScrumwallTask even though it is already defined in the parent Task.

$this->addField('tasktype_id')->refModel('Model_TaskType');

Is that expeced behaviour for inheritance of models ? What is really confusing is that it worked fine on localhost (Windows 7) !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!