1
我有一個模型,我想檢查更多的插件,如果插件加載,然後將模型插入到人模型的插件。我使用這種方法?但在模型和行動上有不同的結果。 另一種方法比構建更多的插件檢查更好。cakephp附加更多屬於
class Comment extends AppModel {
/**
* @see Model::$belongsTo
*/
public $belongsTo = array(
'Content' => array(
'className' => 'Content',
'foreignKey' => 'object_id',
'conditions' => array(
'Comment.object_id = Content.id',
)
),
);
/**
* @see Model::__construct
*/
public function __construct($id = false, $table = null, $ds = null) {
// parent
parent::__construct($id, $table, $ds);
// check for newsstudio
if (CakePlugin::loaded('NewModel')) {
$this->bindModel(
array('belongsTo' => array(
'NewModel' => array(
'className' => 'NewModel.NewModel',
'foreignKey' => 'object_id',
'conditions' => array(
'Comment.object_id = NewModel.id',
)
)
)
));
}
var_dump($this->belongsTo); // correct! NewModel added to blongsto
}
}
// but in action during use. Plugin loaded but
var_dump($this->Comment->belongsTo); // incorrect! just `Content` added