file config:
use Phalcon\Config;
use Phalcon\Logger;
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
$hostname = $_SERVER['HTTP_HOST'];
@date_default_timezone_set('Asia/Ho_Chi_Minh');
return new Config([
'database' => [
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'username',
'password' => 'parssword',
'dbname' => 'dataname',
'charset' => 'utf8',
],
'application' => [
'appDir' => APP_PATH . '/',
'controllersDir' => APP_PATH . '/controllers/',
'modelsDir' => APP_PATH . '/models/',
'formsDir' => APP_PATH . '/forms/',
'viewsDir' => APP_PATH . '/views/',
'migrationsDir' => APP_PATH . '/migrations/',
'pluginsDir' => APP_PATH . '/plugins/',
'libraryDir' => APP_PATH . '/library/',
'cacheDir' => BASE_PATH . '/cache/',
'baseUri' => 'https://'.$hostname.'/',
'publicUrl' => 'https://'.$hostname.'',
'cryptSalt' => 'eEAfR|_&G&f,+vU]:jFr!!A&+71w1Ms9~8_4L!<@[[email protected]_2My|:+.u>/6m,$D'
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
// 'baseUri' => preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]),
],
'logger' => [
'path' => APP_PATH . '/logs/',
'format' => '%date% [%type%] %message%',
'date' => 'D j H:i:s',
'logLevel' => Logger::DEBUG,
'filename' => 'application.log',
],
'mail' => [
'fromName' => 'name',
'fromEmail' => '[email protected]',
'smtp' => [
'server' => 'smtp.gmail.com',
'port' => 587,
'security' => 'tls',
'username' => 'name',
'password' => 'pass'
]
],
// Set to false to disable sending emails (for use in test environment)
'useMail' => true
]);
file service:
/**
* The URL component is used to generate all kind of urls in the application
*/
$di->setShared('url', function () {
$config = $this->getConfig();
$url = new UrlResolver();
$url->setBaseUri($config->application->baseUri);
return $url;
});
/**
* Setting up the view component
*/
$di->set('view', function () {
$config = $this->getConfig();
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->registerEngines([
'.volt' => function ($view) {
$config = $this->getConfig();
$volt = new VoltEngine($view, $this);
$volt->setOptions([
'compiledPath' => $config->application->cacheDir . 'volt/',
'compiledSeparator' => '_'
]);
$volt->getCompiler()->addFunction(
'keywrods',
function($key)
{
return str_replace(" ", ", ", $key);
//return preg_replace(" ", ",", $key);
});
$volt->getCompiler()->addFunction(
'Enjavascript',
function($key)
{
return '<script type="text/javascript"> /<![CDATA[/' . $key . '/]]>/</script>';
});
return $volt;
}
]);
return $view;
}, true);
/*
$di->setShared('view', function () {
$config = $this->getConfig();
$view = new View();
$view->setDI($this);
$view->setViewsDir($config->application->viewsDir);
$view->registerEngines([
'.volt' => function ($view) {
$config = $this->getConfig();
$volt = new VoltEngine($view, $this);
$volt->setOptions([
'compiledPath' => $config->application->cacheDir,
'compiledSeparator' => '_'
]);
return $volt;
},
'.phtml' => PhpEngine::class
]);
return $view;
});*/
/**
* Database connection is created based in the parameters defined in the configuration file
$di->setShared('db', function () {
$config = $this->getConfig();
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
$params = [
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset
];
if ($config->database->adapter == 'Postgresql') {
unset($params['charset']);
}
$connection = new $class($params);
return $connection;
});*/
$di->set('db', function () {
$config = $this->getConfig();
return new DbAdapter([
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset
]);
});
$di->set('mail', function () {
return new Mail();
});
$di->set('modelsMetadata', function ()
{
$config = $this->getConfig();
return new MetaDataAdapter([
'metaDataDir' => $config->application->cacheDir . 'metaData/',
"lifetime" => 60,
]);
if ($config->debug)
{
$cache->flush();
}
});
$di->set('session', function () {
session_save_path('/home/www/mxt.vn/session');
$session = new SessionAdapter();
$session->start();
return $session;
});
/**
* Crypt service
*/
$di->set('crypt', function () {
$config = $this->getConfig();
$crypt = new Crypt();
$crypt->setKey($config->application->cryptSalt);
return $crypt;
});
/**
* Dispatcher use a default namespace
*/
$di->set('dispatcher', function () {
//Create/Get an EventManager
$eventsManager = new \Phalcon\Events\Manager();
//Attach a listener
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
//controller or action doesn't exist
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'notFound'
));
return false;
}
}
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Set default namespace to backend module
$dispatcher->setDefaultNamespace("iChi\Controllers");
//Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
$di->set('auth', function () {
return new Auth();
});
/**
* Register the session flash service with the Twitter Bootstrap classes
*/
$di->set('flash', function () {
return new Flash([
'error' => 'alert alert-danger',
'success' => 'alert alert-success',
'notice' => 'alert alert-info',
'warning' => 'alert alert-warning'
]);
});
$di->set("cookies", function ()
{
$cookies = new Cookies();
$cookies->useEncryption(false);
return $cookies;}
);
$di->setShared('cache', function ()
{
$config = $this->getConfig();
$frontCache = new \Phalcon\Cache\Frontend\Data(array('lifetime' => 60)); //900
$cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => $config->application->cacheDir."caches/"));
return $cache;
});
$di->setShared('modelsCache', function ()
{
$config = $this->getConfig();
//Create a Data frontend and set a default lifetime to 1 hour
$frontCache = new \Phalcon\Cache\Frontend\Data(array('lifetime' => 60)); //900
//Create the cache passing the connection
$cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => $config->application->cacheDir."caches/"));
return $cache;
});
The table name is 'ausers', I do not know where the phalcon is
Help my thanks!