当前位置: 首页>>代码示例>>PHP>>正文


PHP App::db方法代码示例

本文整理汇总了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();
 }
开发者ID:seletskyy,项目名称:blog_mvc,代码行数:33,代码来源:app.class.php

示例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();
 }
开发者ID:vovella,项目名称:homeworks,代码行数:29,代码来源:app.class.php

示例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();
 }
开发者ID:janson-git,项目名称:testLivetexHtmlParser,代码行数:7,代码来源:ResultController.php

示例4: getDatabase

 static function getDatabase()
 {
     if (!self::$db) {
         self::$db = new Database('root', '', 'common-database');
     }
     return self::$db;
 }
开发者ID:Harmeko,项目名称:tweet_academie,代码行数:7,代码来源:App.php

示例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));
         }
     }
 }
开发者ID:hhz1084,项目名称:pyz,代码行数:26,代码来源:User.class.php

示例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();
 }
开发者ID:Skynet2004x,项目名称:SkynetPR,代码行数:28,代码来源:app.class.php

示例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);
 }
开发者ID:laiello,项目名称:php-simple-webgame-framework,代码行数:7,代码来源:Model.class.php

示例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();
 }
开发者ID:Denbora,项目名称:mvc_phpAcademy,代码行数:26,代码来源:app.class.php

示例9: getDatabase

 static function getDatabase()
 {
     if (!self::$db) {
         self::$db = new Database(DB_LOGIN, DB_PASS, DB_NAME);
     }
     return self::$db;
 }
开发者ID:Polou,项目名称:GoldAdventure,代码行数:7,代码来源:App.php

示例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;
 }
开发者ID:hhz1084,项目名称:pyz,代码行数:7,代码来源:App.class.php

示例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();
 }
开发者ID:rganin,项目名称:magelight,代码行数:11,代码来源:AppTest.php

示例12: db

 /**
  * @return Db
  */
 public static function db()
 {
     if (is_null(self::$db)) {
         self::$db = new Db();
     }
     return self::$db;
 }
开发者ID:janson-git,项目名称:testLivetexHtmlParser,代码行数:10,代码来源:App.php

示例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();
 }
开发者ID:Tidynar,项目名称:University,代码行数:8,代码来源:App.php

示例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;
 }
开发者ID:bhaktaraz,项目名称:TestableCode,代码行数:9,代码来源:UserService.php

示例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';
 }
开发者ID:kovvy,项目名称:shop,代码行数:10,代码来源:index.php


注:本文中的App::db方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。