このリンクからフィードバック プラグインを使用して、PolymorphicBehavior を使用してアプリケーション内の任意のモデルにコメントを追加しています。アプリで次のような 2 つのエラーが表示されます
厳密 (2048): PolymorphicBehavior::setup() の宣言は ModelBehavior::setup(Model $model, $config = Array) [APP\Plugin\Feedback\Model\Behavior\PolymorphicBehavior.php, line 93] と互換性がある必要があります
Strict (2048): PolymorphicBehavior::afterFind() の宣言は ModelBehavior::afterFind(Model $model, $results, $primary) [APP\Plugin\Feedback\Model\Behavior\PolymorphicBehavior.php, line 93] と互換性がある必要があります
これらのエラーの原因は不明です。誰かが私を助けることができれば、それは素晴らしいことです. これが私の PolymorphicBehavior.php のコードです。93行目はコードの最後の行ではありません
<?php
App::uses('ModelBehavior', 'Model');
//PolymorphicBehavior class
class PolymorphicBehavior extends ModelBehavior {
//defaultSettings property
protected $_defaultSettings = array(
'modelField' => 'model',
'foreignKey' => 'foreign_key'
);
// setup method
public function setup($Model, $settings = array()) {
if (!isset($this->settings[$Model->alias])) {
$this->settings[$Model->alias] = $this->_defaultSettings;
}
$this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], (array) $settings);
}
//afterFind method
public function afterFind($Model, $results, $primary = false) {
extract($this->settings[$Model->alias]);
if (App::import('Vendor', 'MiCache')) {
$models = MiCache::mi('models');
} else {
$models = App::objects('Model');
}
if ($primary && isset($results[0][$Model->alias][$modelField]) && isset($results[0][$Model->alias][$foreignKey]) && $Model->recursive > 0) {
foreach ($results as $key => $result) {
$associated = array();
$model = Inflector::classify($result[$Model->alias][$modelField]);
$foreignId = $result[$Model->alias][$foreignKey];
if ($model && $foreignId && in_array($model, $models)) {
$result = $result[$Model->alias];
if (!isset($Model->$model)) {
$Model->bindModel(array('belongsTo' => array(
$model => array(
'conditions' => array($Model->alias . '.' . $modelField => $model),
'foreignKey' => $foreignKey
)
)));
}
$conditions = array($model . '.' . $Model->$model->primaryKey => $result[$foreignKey]);
$recursive = -1;
$associated = $Model->$model->find('first', compact('conditions', 'recursive'));
$name = $Model->$model->display($result[$foreignKey]);
$associated[$model]['display_field'] = $name?$name:'*missing*';
$results[$key][$model] = $associated[$model];
}
}
} elseif(isset($results[$Model->alias][$modelField])) {
$associated = array();
$model = Inflector::classify($result[$Model->alias][$modelField]);
$foreignId = $results[$Model->alias][$foreignKey];
if ($model && $foreignId) {
$result = $results[$Model->alias];
if (!isset($Model->$model)) {
$Model->bindModel(array('belongsTo' => array(
$model => array(
'conditions' => array($Model->alias . '.' . $modelField => $model),
'foreignKey' => $foreignKey
)
)));
}
$conditions = array($model . '.' . $Model->$model->primaryKey => $result[$foreignKey]);
$recursive = -1;
$associated = $Model->$model->find('first', compact('conditions', 'recursive'));
$name = $Model->$model->display($result[$foreignKey]);
$associated[$model]['display_field'] = $name?$name:'*missing*';
$results[$model] = $associated[$model];
}
}
return $results;
}
//display method
public function display($Model, $id = null) {
if (!$id) {
if (!$Model->id) {
return false;
}
$id = $Model->id;
}
return current($Model->find('list', array('conditions' => array($Model->alias . '.' . $Model->primaryKey => $id))));
}
}