My folder/namespace hierarchy:

  • app/models/entities
    • Entities.php
    • people
      • People.php
      • (other models)

I followed the instructions per this question: lithium fill multiple models from view, but got an error "failed to open stream: No such file or directory in C:\xampp\htdocs\PhiCRM\libraries\lithium\core\Libraries.php on line 468", which, yea... cuz as you saw above, its nested in another folder, which is indicated in the configs array, shown below

My fix: I changed

public $belongsTo = array(
    'People' => array(
        'class' => '\app\models\entities\people\People',
        'key' => 'person_id',
    ),
);

to

public $belongsTo = array(
    'people\People' => array(
        'class' => '\app\models\entities\people\People',
        'key' => 'person_id',
    ),
);

and now the error goes away (changed the second line, from 'People' to 'people\People'), but now I get the error: 'Related model class 'app\models\entities\people\people\People' not found.' in C:\xampp\htdocs\PhiCRM\libraries\lithium\data\model\Relationship.php on line 159, so now its tacking on ANOTHER people to the path string.

My question: Is this intended behavior? Shouldn't the relationships model use the class path I provided in the $configs array instead of string concatenation with the class name? If its a bug, should I report it, and how?

有帮助吗?

解决方案

public $belongsTo = array(
    'People' => array(
        'to' => '\app\models\entities\people\People',
        'key' => 'person_id',
    ),
);

Should work better with 'to' instead of 'class' ;-)

其他提示

In librarires/lithium/data/model/Relashionships.php, ln 115, the original code is:

    if (!$config['to']) {
        $assoc = preg_replace("/\\w+$/", "", $config['from']) . $name;  
        $config['to'] = Libraries::locate('models', $assoc);
    }

Changed to

    if (!$config['to']) {
        if(!$config['class']){
            $assoc = preg_replace("/\\w+$/", "", $config['from']) . $name;  
        }
        else{
            $assoc = $config['class'];
        }
        $config['to'] = Libraries::locate('models', $assoc);
    }

Seems the framework assumes related models will be in the same namespace. I changed it so that if the class config is filled out in the relationships declaration in the model, it will use that instead.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top