本文整理汇总了PHP中app\Config::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::instance方法的具体用法?PHP Config::instance怎么用?PHP Config::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Config
的用法示例。
在下文中一共展示了Config::instance方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Подключение шаблонизатора Twig
*/
public function __construct()
{
$config = \App\Config::instance();
$templates_dir = $config->data['templates']['dir'];
$loader = new \Twig_Loader_Filesystem($templates_dir);
$this->twig = new \Twig_Environment($loader);
}
示例2: __construct
protected function __construct()
{
$config = Config::instance();
try {
$this->dbh = $this->getPdoObj($config);
} catch (\PDOException $e) {
throw new DbException('Не удалось подключиться к БД ' . '<br>' . $e->getMessage());
}
}
示例3: __construct
private function __construct()
{
$dbc = Config::instance()['db'];
$dsn = $dbc->driver . ':host=' . $dbc->host . ';dbname=' . $dbc->dbname . ';charset=' . ($dbc->charset ?? 'utf8');
try {
$this->dbh = new \PDO($dsn, $dbc->user, $dbc->password);
$this->dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) {
\App\Notifier::instance()->notify('Database problems!!!', 'Cannot connect to database!!!');
throw new \App\Exceptions\Db(null, 1, $e);
}
}
示例4: __construct
/**
* Установка соединения с БД
*/
public function __construct()
{
$config = \App\Config::instance();
foreach ($config->data['db'] as $property => $value) {
${$property} = $value;
}
$dsn = 'mysql:host=' . $host . ';dbname=' . $dbname;
try {
$this->dbh = new \PDO($dsn, $username, $password);
} catch (\PDOException $e) {
throw new \App\Exceptions\Db('Нет соединения с БД');
}
}
示例5: __construct
/**
* Создание объекта подключения к БД
*/
public function __construct()
{
$config = App\Config::instance();
$param1 = 'mysql:host=' . $config->data['db']['host'] . ';dbname=' . $config->data['db']['dbname'];
self::$DbName = $config->data['db']['dbname'];
$param2 = $config->data['db']['login'];
$param3 = $config->data['db']['pass'];
try {
$this->dbh = new \PDO($param1, $param2, $param3);
//Добавлены атрибуты подключения (режимы выброса исключений)
$this->dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) {
$mailer = new \App\SwMailer();
$res = $mailer->sendMail('Проблемы БД', 'Потеря соединения с БД', 1);
$msg = !$res ? 'Неудачная попытка оповещения администратора' : 'Администратор оповещен';
throw new \App\Exceptions\DB('Некорректные параметры подключения к БД. ' . $msg . ' ');
}
}
示例6: check
<?php
require __DIR__ . '/tests.php';
$config = \App\Config::instance();
/**
* Check if parameter 'db' exists in config
*/
echo check($config->db, 'Config->db');
/**
* Check if key 'host' exists in parameter 'db' of config
*/
echo check(isset($config->db['host']), 'Config->db[host]');
示例7: actionTable
protected function actionTable()
{
$funcs = Config::instance()->funcs;
$table = new AdminDataTable([1, 2, 3, 4, 5], $funcs);
$table->render1();
$this->view->render('/admin/table.html', ['data' => $table->data, 'func' => $table->namefunc, 'resource' => \PHP_Timer::resourceUsage()]);
}
示例8: __construct
protected function __construct()
{
$config = Config::instance();
$this->dbh = new \PDO($config->data['db']['driver'] . ':host=' . $config->data['db']['host'] . ';dbname=' . $config->data['db']['dbname'], $config->data['db']['user'], $config->data['db']['password']);
}
示例9: __construct
/**
* Получение пути к файлу с логами
*/
public function __construct()
{
$config = \App\Config::instance();
$this->file = $config->data['log']['file'];
}