Hi Phalcon, Long time no see. I have a prolem, Because request, I want to set service in controller infoDbAction and access it.
When i redirect to page adminAccount this error:
Please see code:
<?php
public function infoDbAction() {
if ($this->request->isPost()) {
$messages = '';
$params = array_merge($this->request->getPost(), $_FILES);
try {
$info = [
"adapter" => "Mysql",
"host" => $params['dbhost'],
"username" => $params['uname'],
"password" => $params['pwd'],
"dbname" => $params['dbname']
];
$db = new \Phalcon\Db\Adapter\Pdo\Mysql($info);
if ($db) {
$di = $this->getDI();
$di->set(
"db",
function () use($info) {
return new \Phalcon\Db\Adapter\Pdo\Mysql(
$info
);
}
);
$this->response->redirect('index/adminAccount');
//$this->di->get("db");
//$this->view->disable();
}
} catch (Exception $e) {
$messages = '<b>Error when initializing database connection:</b>' . $e->getMessage();
}
}
$this->view->messages = $messages;
}
public function adminAccountAction() {
//$this->di->get("db");
//this error
$db = $this->getDI()->get('db');
/*$sql = "INSERT INTO user (name) VALUE (?)";
$db->execute($sql, ['aaaa']);*/
}
Please help me, thanks you