Hello friends, I am trying to use PHQL in my phalcon app but I a not able to understand how it works. I tried different ways to use mysql quesries by PHQL. But now I am getting error 404 page.
My public/index.php file has this codes
$di->set('modelsManager', function() {
return new Phalcon\Mvc\Model\Manager();
});
my sessions.php model has these codes,
<?php
class Sessions extends \Phalcon\Mvc\Model
{
/**
*
* @var integer
*/
public $id;
/**
*
* @var string
*/
public $skey;
/**
*
* @var string
*/
public $time;
/**
* Independent Column Mapping.
*/
public function columnMap()
{
return array(
'id' => 'id',
'skey' => 'skey',
'time' => 'time'
);
}
//constructor to set session
public function setSessions(){
if(!isset($_SESSION['CSRF'])){
$_SESSION['CSRF'] = self::getSessionKey(self::generateKey());
}
}
public function getSessionKey($var){
$query = $this->modelsManager->createQuery("SELECT * FROM sessions WHERE skey = :skey:");
$session = $query->execute(array(
'skey' => $var
));
}
public function generateKey(){
$charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_';
$len = 7;
$numrows = 1;
$csrf_token = '';
while($numrows != 0 AND strlen($csrf_token) < 8 ){
for($i = 0; $i <= $len; $i++){
$rand = rand()% strlen($charset);
$temp = substr($charset, $rand, 1);
$csrf_token .= $temp;
}
$time = time();
$find_query = "SELECT `id` FROM `sessions` WHERE BINARY `skey` = '$csrf_token' AND `time` < '$time'";
$query = new Phalcon\Mvc\Model\Query($find_query);
}
return $query;
}
}
and my index action in index controller has these codes
$session = new Sessions();
$session->setSession();
I tried to follow documentation but I am not able to get it. Can anyone tell me which page should have which codes? And if anyone can suggest me some tutorials to use mysql in phalcon, please let me know.