Hi community,
I have a problem using APC meta-data in my app and trying save a data.
Declaration models meta-data in DI:
$di->set('modelsMetadata', function() use ($di){
$metaData = new Phalcon\Mvc\Model\MetaData\Apc(array(
'lifetime' => 86400,
'prefix' => 'metadata_'
));
return $metaData;
});
Model Sessions:
class Sessions extends Phalcon\Mvc\Model {
/** @var int ID session auto_increment */
public $id;
/** @var int ID user */
public $id_user;
/** @var string Session hash */
public $hash;
/** @var int User IP */
public $ip;
/** @var string Selected language */
public $language;
/** @var string Date activity */
public $date_activity;
public function initialize(){
$this->hasOne('id_user', 'Users', 'id', array('alias' => 'user'));
}
Saving data using Phalcon\Mvc\Model:
$session = new Sessions();
$session->id_user = $user->id;
$session->hash = $someHash;
$session->ip = ip2long($this->request->getClientAddress());
$session->date_activity = time();
$session->language = Language::getDefault();
$session->save();
Output after saving:
Notice: Undefined index: 1 in phalcon/mvc/model/metadata.zep on line 276 in /var/www/auction-dev/data/www/test-dev/backend/controllers/client/AuthController.php on line 79
Phalcon\Mvc\Model\Exception:The meta-data is invalid or is corrupt
File = phalcon/mvc/model/metadata.zep
Line = 391
0 [internal function]: Phalcon\Mvc\Model\MetaData->getPrimaryKeyAttributes(Object(Sessions))
1 [internal function]: Phalcon\Mvc\Model->_exists(Object(Phalcon\Mvc\Model\MetaData\Apc), Object(Phalcon\Db\Adapter\Pdo\Mysql), 'sessions')
2 /var/www/auction-dev/data/www/test-dev/backend/controllers/client/AuthController.php(79): Phalcon\Mvc\Model->save()
3 [internal function]: AuthController->loginAction()
4 [internal function]: Phalcon\Dispatcher->dispatch()
5 /var/www/auction-dev/data/www/test-dev/index.php(276): Phalcon\Mvc\Application->handle()
6 {main}
What am I doing wrong? Thanks.
UPD
I tried manually get primary attributes and keys of model, but result remains the same:
$session = new Sessions();
echo '<pre>'.print_r($this->modelsMetadata->getAttributes($session), true).'</pre>';
echo '<pre>'.print_r($this->modelsMetadata->getNonPrimaryKeyAttributes($session), true).'</pre>';
echo '<pre>'.print_r($this->modelsMetadata->getPrimaryKeyAttributes($session), true).'</pre>';
Output is:
Array
(
[0] => id
[1] => id_user
[2] => hash
[3] => ip
[4] => language
[5] => date_activity
)
Array
(
[0] => id_user
[1] => hash
[2] => ip
[3] => language
[4] => date_activity
)
Notice: Undefined index: 1 in phalcon/mvc/model/metadata.zep on line 276 in /var/www/auction-dev/data/www/test-dev/backend/controllers/client/AuthController.php on line 74
Phalcon\Mvc\Model\Exception:The meta-data is invalid or is corrupt
File = phalcon/mvc/model/metadata.zep
Line = 391
0 /var/www/auction-dev/data/www/test-dev/backend/controllers/client/AuthController.php(74): Phalcon\Mvc\Model\MetaData->getPrimaryKeyAttributes(Object(Sessions))
1 [internal function]: AuthController->loginAction()
2 [internal function]: Phalcon\Dispatcher->dispatch()
3 /var/www/auction-dev/data/www/test-dev/index.php(276): Phalcon\Mvc\Application->handle()
4 {main}