I a making a plugin in CakePhp and I am using multiple models inside the plugin. I created those models by using the console and baked them. I ran into a problem when using 1 of them and it only appears with this specific model.
The model file name:
GamificationBadgeUnlockActionProgression.php
Content of model:
<?php
App::uses('GamificationAppModel', 'Gamification.Model');
class GamificationBadgeUnlockActionProgression extends GamificationAppModel {
function __construct() {
parent::__construct();
echo 'oleej';
exit;
}
public $belongsTo = array(
'GamificationBadgeProgression' => array(
'className' => 'GamificationBadgeProgression',
'foreignKey' => 'gamification_badge_progression_id'
),
'GamificationBadgeUnlockAction' => array(
'className' => 'GamificationBadgeUnlockAction',
'foreignKey' => 'gamification_badge_unlock_action_id'
)
);
public function addMissingProgression($missingProgression)
{
/*$this->saveMany($missingProgression, array(
'fieldlist' => array('gamification_badge_progression_id', 'gamification_badge_unlock_action_id')
));*/
}
}
In the controller of the plugin I have:
public $uses = array('Gamification.GamificationBadge',
'Gamification.GamificationBadgeProgression',
'Gamification.GamificationBadgeUnlockAction',
'Gamification.GamificationBadgeUnlockActionProgression',
'Gamification.GamificationBadgeUnlockType');
All the other models are being loaded, except 'Gamification.GamificationBadgeUnlockActionProgression'. Which is very weird. It has all required stuff and it follows the naming conventions and everything. It just isn't being loaded as the constructor is never called and the echo is never shown.
When I call the function from the model like this with an array as parameter:
$this->GamificationBadgeUnlockActionProgression->addMissingProgression($missingProgression);
Then I get an error
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'addMissingProgression' at line 1
Because the model is not loaded.
However CakePhp does create a magic model with the same name, which results in the error above, because the model magically excists but the function ofcourse doesnt and neither do the relations.
What am I missing here?
ClassRegistry::isKeySet('Name of your model');
– Fazal Rasel