I am using a Feedback Plugin from this link to add comments on any model in my application using the PolymorphicBehavior. I am geeting 2 errors on my app that says
Strict (2048): Declaration of PolymorphicBehavior::setup() should be compatible with ModelBehavior::setup(Model $model, $config = Array) [APP\Plugin\Feedback\Model\Behavior\PolymorphicBehavior.php, line 93]
Strict (2048): Declaration of PolymorphicBehavior::afterFind() should be compatible with ModelBehavior::afterFind(Model $model, $results, $primary) [APP\Plugin\Feedback\Model\Behavior\PolymorphicBehavior.php, line 93]
Not to sure what is causing these errors. If anyone could help me out, that would be awesome. Here is the code for my PolymorphicBehavior.php. Please not line 93 is the last line in the code
<?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))));
}
}
Just tweak the plug-in files to make the suggested changes. The reference implementations is this:
// /lib/Cake/Model/ModelBehavior.php
public function setup(Model $model, $config = array()) {
public function afterFind(Model $model, $results, $primary) {
... so you need to change this:
public function setup($Model, $settings = array()) {
public function afterFind($Model, $results, $primary = false) {
... into this:
public function setup(Model $Model, $settings = array()) {
public function afterFind(Model $Model, $results, $primary) {
If you still get too many errors, you might need to hide strict warnings or switch to a better plug-in.