本文整理汇总了PHP中App::db方法的典型用法代码示例。如果您正苦于以下问题:PHP App::db方法的具体用法?PHP App::db怎么用?PHP App::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App
的用法示例。
在下文中一共展示了App::db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public static function run($uri)
{
self::$router = new Router($uri);
self::$db = new DB(config::get('db.host'), config::get('db.name'), config::get('db.user'), config::get('db.password'));
Lang::load(self::$router->getLanguage());
if ($_POST and (isset($_POST['username_in']) and isset($_POST['password_in'])) or isset($_POST['exit'])) {
$us = new RegisterController();
if (isset($_POST['exit'])) {
$us->LogOut();
} else {
$us->Login($_POST);
}
}
if (self::$router->getController() == 'admin' and !Session::getSession('root') or self::$router->getController() == 'myblog' and !Session::getSession('id')) {
self::$router->setController(Config::get('default_controller'));
self::$router->setAction(Config::get('default_action'));
Session::setSession('message', 'Отказ в доступе');
}
$controller_class = ucfirst(self::$router->getController()) . 'Controller';
$controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction());
$controller_object = new $controller_class();
if (method_exists($controller_object, $controller_method)) {
$controller_object->{$controller_method}();
$view_object = new View($controller_object->getData());
$content = $view_object->render();
} else {
throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist');
}
$layout = self::$router->getRoute();
$layout_path = VIEWS_PATH . DS . $layout . '.html';
$layout_view_object = new View(compact('content'), $layout_path);
echo $layout_view_object->render();
}
示例2: run
public static function run($uri)
{
self::$router = new Router($uri);
# создаем обект базы данных и передаем параметры подключения
self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
Lang::load(self::$router->getLanguage());
$controller_class = ucfirst(self::$router->getController()) . 'Controller';
$controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction());
# при каждом запросе к руту admin выполняется проверка, имеет ли пользователь на это права
$layout = self::$router->getRoute();
if ($layout == 'admin' && Session::get('role') != 'admin') {
if ($controller_method != 'admin_login') {
Router::redirect('/admin/users/login');
}
}
// Calling controller's method
$controller_object = new $controller_class();
if (method_exists($controller_object, $controller_method)) {
$view_path = $controller_object->{$controller_method}();
$view_object = new View($controller_object->getData(), $view_path);
$content = $view_object->render();
} else {
throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.');
}
# код віполняющий рендеринг
$layout_path = VIEWS_PATH . DS . $layout . '.html';
$layout_view_object = new View(compact('content'), $layout_path);
echo $layout_view_object->render();
}
示例3: viewAction
public function viewAction($id)
{
$result = \App::db()->query("SELECT * FROM parsing_data WHERE `id` = ?", array($id))->fetch();
$data = unserialize($result['data']);
$this->view->assign('data', $data);
$this->view->render();
}
示例4: getDatabase
static function getDatabase()
{
if (!self::$db) {
self::$db = new Database('root', '', 'common-database');
}
return self::$db;
}
示例5: actionLogin
public function actionLogin()
{
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$validate = isset($_POST['validate']) ? trim($_POST['validate']) : '';
if (empty($username) || empty($password) || empty($validate)) {
$this->location('/', array('error' => '参数错误'));
}
if (!ValidateCode::checkCode($validate)) {
$msg = '验证码错误';
$this->location('/', array('error' => $msg));
} else {
$sql = "SELECT * FROM ha_user WHERE usertype=4 and userstatus=1 and userid='{$username}' and password='{$password}'";
$data = App::db()->getRow($sql);
if (!empty($data)) {
$_SESSION['user'] = $data;
$_SESSION['is_login'] = 1;
$code = 200;
$this->location('/', array('m' => 'main'));
} else {
$code = 401;
$msg = '用户名或密码错误';
$this->location('/', array('error' => $msg));
}
}
}
示例6: run
public static function run($uri)
{
self::$router = new Router($uri);
self::$db = DB::getInstance(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
Lang::load(self::$router->getLanguage());
$controller_class = ucfirst(self::$router->getController()) . 'controller';
$controller_method = strtolower(self::$router->getMethod_prefix() . self::$router->getAction());
$controller_parametr = self::$router->getParams();
$layout = self::$router->getRoute();
if ($layout == 'admin' && Session::get('role') != 'admin') {
if ($controller_method != 'admin_login') {
Router::redirect('/admin/users/login');
}
}
//Calling conrollers method
$controller_object = new $controller_class();
if (method_exists($controller_object, $controller_method)) {
$view_path = $controller_object->{$controller_method}();
$view_object = new View($controller_object->getData(), $view_path);
$content = $view_object->render();
} else {
throw new Exception('Метод ' . $controller_method . ' в классе ' . $controller_class . 'не найден');
}
$layout_path = VIEW_PATH . DS . $layout . '.html';
$layout_view_object = new View(compact('content'), $layout_path);
// основной рендер вывода страниц
echo $layout_view_object->render();
}
示例7: __construct
public function __construct()
{
$this->db = App::db();
$db_map = App::conf('db_map');
$this->db_name = current(array_keys($db_map));
$this->db->usedb($this->db_name);
}
示例8: run
public static function run($uri)
{
self::$router = new Router($uri);
self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
Lang::load(self::$router->getLanguage());
$controller_class = ucfirst(self::$router->getController()) . "Controller";
$controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction());
$layout = self::$router->getRoute();
if ($layout == "admin" && Session::get("role") != "admin") {
if ($controller_method != "admin_login") {
Router::redirect("/admin/users/login");
}
}
//Calling controller's method
$controller_object = new $controller_class();
if (method_exists($controller_object, $controller_method)) {
$view_path = $controller_object->{$controller_method}();
$view_object = new View($controller_object->getData(), $view_path);
$content = $view_object->render();
} else {
throw new Exception("Method {$controller_method} does not exist in {$controller_class}");
}
$layout_path = VIEWS_PATH . DS . $layout . ".html";
$layout_view_object = new View(compact('content'), $layout_path);
echo $layout_view_object->render();
}
示例9: getDatabase
static function getDatabase()
{
if (!self::$db) {
self::$db = new Database(DB_LOGIN, DB_PASS, DB_NAME);
}
return self::$db;
}
示例10: db
public static function db()
{
if (self::$db == null) {
self::$db = new Mysql(DB_HOST, DB_USER, DB_PASS, DB_NAME, 3306);
}
return self::$db;
}
示例11: testDbEmptyConfig
/**
* @expectedException \Magelight\Exception
* @expectedExceptionMessage Database `default` configuration not found.
*/
public function testDbEmptyConfig()
{
$mysqlConfig = null;
$index = \Magelight\App::DEFAULT_INDEX;
$this->configMock->expects($this->once())->method('getConfig')->with('/global/db/' . $index, null)->will($this->returnValue($mysqlConfig));
$this->app->db();
}
示例12: db
/**
* @return Db
*/
public static function db()
{
if (is_null(self::$db)) {
self::$db = new Db();
}
return self::$db;
}
示例13: start
public static function start()
{
$router = new Router();
self::$db = self::loadDb();
self::$auth = self::loadAuth();
self::$access = self::loadAccess();
self::$router = $router::init();
}
示例14: getCurrentUser
public function getCurrentUser()
{
$userId = $_SESSION['user_id'];
$user = App::db()->select('id, username')->where('id', $userId)->limit(1)->get();
if ($user->num_results() > 0) {
return $user->row();
}
return false;
}
示例15:
function __construct()
{
$login = 'root';
$password = '';
$host = 'localhost';
$db = 'site';
$this->search();
self::$db = $this->connectDB($login, $password, $host, $db);
include_once 'Engine/Module.class.php';
}