本文整理汇总了PHP中App::init方法的典型用法代码示例。如果您正苦于以下问题:PHP App::init方法的具体用法?PHP App::init怎么用?PHP App::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App
的用法示例。
在下文中一共展示了App::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bootstrap
/**
* Initializes configure and runs the bootstrap process.
* Bootstrapping includes the following steps:
*
* - Setup App array in Configure.
* - Include app/Config/core.php.
* - Configure core cache configurations.
* - Load App cache files.
* - Include app/Config/bootstrap.php.
* - Setup error/exception handlers.
*
* @param boolean $boot
* @return void
*/
public static function bootstrap($boot = true)
{
if ($boot) {
self::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT));
if (!(include APP . 'Config' . DS . 'core.php')) {
trigger_error(__d('cake_dev', "Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR);
}
App::$bootstrapping = false;
App::init();
App::build();
if (!(include APP . 'Config' . DS . 'bootstrap.php')) {
trigger_error(__d('cake_dev', "Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR);
}
$level = -1;
if (isset(self::$_values['Error']['level'])) {
error_reporting(self::$_values['Error']['level']);
$level = self::$_values['Error']['level'];
}
if (!empty(self::$_values['Error']['handler'])) {
set_error_handler(self::$_values['Error']['handler'], $level);
}
if (!empty(self::$_values['Exception']['handler'])) {
set_exception_handler(self::$_values['Exception']['handler']);
}
}
}
示例2: run
public function run()
{
// Разбиваем внутренний путь на сегменты.
$segments = explode('/', $this->getUri());
// Первый сегмент — контроллер.
$controllerName = array_shift($segments);
$namespace = App::init()->controllerNameSpace;
//имя контролллера
$controllerName = $controllerName ? $controllerName : App::init()->defaultRoute['controller'];
//Если нет контроллера, выбираем дефлотный контроллер
//namespace+ИмяКонтролллера+Controller
$controllerFullName = $namespace . ucfirst($controllerName) . 'Controller';
//Новый контролллер
$this->controller = new $controllerFullName($controllerName);
// Второй — действие.
$action = ucfirst(array_shift($segments));
//Определяем действие. Если нет действия, выбираем дефлотное действие
$this->action = $action ? 'action' . $action : 'action' . App::init()->defaultRoute['action'];
// Остальные сегменты — параметры.
$this->parameters = $segments;
//отправляем роутер в настройку приложения
App::init()->router = $this;
// Если не загружен нужный класс контроллера или в нём нет
// нужного метода — 404
if (!is_callable(array($this->controller, $this->action))) {
header("HTTP/1.0 404 Not Found");
return;
}
// Вызываем действие контроллера с параметрами
call_user_func_array(array($this->controller, $this->action), $this->params);
// Ничего не применилось. 404.
// header("HTTP/1.0 404 Not Found");
return;
}
示例3: run
/**
* 运行控制器
* @access public
* @return void
*/
public static function run()
{
App::init();
//检查服务器是否开启了zlib拓展
if (C('GZIP_OPEN') && extension_loaded('zlib') && function_exists('ob_gzhandler')) {
ob_end_clean();
ob_start('ob_gzhandler');
}
//API控制器
if (APP_NAME == 'api') {
App::execApi();
//Widget控制器
} elseif (APP_NAME == 'widget') {
App::execWidget();
//Plugin控制器
} elseif (APP_NAME == 'plugin') {
App::execPlugin();
//APP控制器
} else {
App::execApp();
}
//输出buffer中的内容,即压缩后的css文件
if (C('GZIP_OPEN') && extension_loaded('zlib') && function_exists('ob_gzhandler')) {
ob_end_flush();
}
if (C('LOG_RECORD')) {
Log::save();
}
return;
}
示例4: bootstrap
/**
* Initializes configure and runs the bootstrap process.
* Bootstrapping includes the following steps:
*
* - Setup App array in Configure.
* - Include app/Config/core.php.
* - Configure core cache configurations.
* - Load App cache files.
* - Include app/Config/bootstrap.php.
* - Setup error/exception handlers.
*
* @param bool $boot Whether to do bootstrapping.
*
* @return void
*/
public static function bootstrap($boot = TRUE)
{
if ($boot) {
static::_appDefaults();
if (!(include APP . 'Config' . DS . 'core.php')) {
trigger_error(__d('cake_dev', "Can't find application core file. Please create %s, and make sure it is readable by PHP.", APP . 'Config' . DS . 'core.php'), E_USER_ERROR);
}
App::init();
App::$bootstrapping = FALSE;
App::build();
$exception = array('handler' => 'ErrorHandler::handleException');
$error = array('handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED);
if (PHP_SAPI === 'cli') {
App::uses('ConsoleErrorHandler', 'Console');
$console = new ConsoleErrorHandler();
$exception['handler'] = array($console, 'handleException');
$error['handler'] = array($console, 'handleError');
}
static::_setErrorHandlers($error, $exception);
if (!(include APP . 'Config' . DS . 'bootstrap.php')) {
trigger_error(__d('cake_dev', "Can't find application bootstrap file. Please create %s, and make sure it is readable by PHP.", APP . 'Config' . DS . 'bootstrap.php'), E_USER_ERROR);
}
restore_error_handler();
static::_setErrorHandlers(static::$_values['Error'], static::$_values['Exception']);
// Preload Debugger + CakeText in case of E_STRICT errors when loading files.
if (static::$_values['debug'] > 0) {
class_exists('Debugger');
class_exists('CakeText');
}
}
}
示例5: initZend
function initZend()
{
// Use ZF autoloader
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
// Get the application factories helper
require_once APPLICATION_PATH . '/App.php';
App::init($application);
$application->bootstrap();
// Hack: Inject the bootstrap in the front controller instance to
// make the Zend_Application resources available to the Service layer
$bootstrap = $application->getBootstrap();
Zend_Controller_Front::getInstance()->setParam('bootstrap', $bootstrap);
if (getenv('PHPUNIT_NOCLEAN') != 1) {
// Dropping the database and loading the initial fixtures
echo "Please, be patient. Loading fixtures in " . APPLICATION_ENV . " database. This may take some seconds...\n";
$mongo = \App::getMongoDB();
$mongo->drop();
exec("APPLICATION_DB_PREFIX=\"" . APPLICATION_DB_PREFIX . "\" php " . APPLICATION_SCRIPTS_PATH . "/update.php --env " . APPLICATION_ENV);
exec("APPLICATION_DB_PREFIX=\"" . APPLICATION_DB_PREFIX . "\" php " . APPLICATION_SCRIPTS_PATH . "/aclLoader.php --env testing --drop ");
// Remove slots in fixtures, avoiding problems with indexes
$mongo->steering->remove(array('resId' => array('$in' => array(15, 69))), array('justOne' => false));
exec("APPLICATION_DB_PREFIX=\"" . APPLICATION_DB_PREFIX . "\" php " . APPLICATION_SCRIPTS_PATH . "/load.mongodb.php --env " . APPLICATION_ENV);
exec("APPLICATION_DB_PREFIX=\"" . APPLICATION_DB_PREFIX . "\" php " . APPLICATION_SCRIPTS_PATH . "/load.brands.php --env " . APPLICATION_ENV);
}
}
示例6: bootstrap
/**
* Initializes configure and runs the bootstrap process.
* Bootstrapping includes the following steps:
*
* - Setup App array in Configure.
* - Include app/Config/core.php.
* - Configure core cache configurations.
* - Load App cache files.
* - Include app/Config/bootstrap.php.
* - Setup error/exception handlers.
*
* @param boolean $boot
* @return void
*/
public static function bootstrap($boot = true)
{
if ($boot) {
self::_appDefaults();
if (!(include APP . 'Config' . DS . 'core.php')) {
trigger_error(__d('cake_dev', "Can't find application core file. Please create %s, and make sure it is readable by PHP.", APP . 'Config' . DS . 'core.php'), E_USER_ERROR);
}
App::init();
App::$bootstrapping = false;
App::build();
$exception = array('handler' => 'ErrorHandler::handleException');
$error = array('handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED);
self::_setErrorHandlers($error, $exception);
if (!(include APP . 'Config' . DS . 'bootstrap.php')) {
trigger_error(__d('cake_dev', "Can't find application bootstrap file. Please create %s, and make sure it is readable by PHP.", APP . 'Config' . DS . 'bootstrap.php'), E_USER_ERROR);
}
restore_error_handler();
self::_setErrorHandlers(self::$_values['Error'], self::$_values['Exception']);
// Preload Debugger + String in case of E_STRICT errors when loading files.
if (self::$_values['debug'] > 0) {
class_exists('Debugger');
class_exists('String');
}
}
}
示例7: init
/**
*
* Initialization
*/
public function init()
{
parent::init();
if (isset($_GET['id'])) {
$q = $this->getQuery();
$this->item = $q->findOneById($_GET['id']);
}
}
示例8: testInit
public function testInit()
{
$this->sessionMock->expects($this->once())->method('setLifetime')->will($this->returnSelf());
$this->sessionMock->expects($this->once())->method('setSessionName')->will($this->returnSelf());
$this->translatorMock->expects($this->once())->method('loadTranslations');
$this->app->init();
$this->assertEquals(\Magelight\App::DEFAULT_LANGUAGE, $this->app->getLang());
}
示例9: run
public static function run()
{
\Core\Hook::listen('app_begin');
App::init();
// Session初始化
session(C('SESSION_OPTIONS'));
App::exec();
\Core\Hook::listen('app_end');
}
示例10: init
protected function init()
{
parent::init();
$q = $this->getItemQuery();
if (isset($_GET['id']) && $_GET['id']) {
$this->data = $q->findOneById($_GET['id']);
}
if ($this->data) {
$this->other = $this->getOtherItem();
}
}
示例11: run
public static function run()
{
//项目初始化
App::init();
//不过php执行方式不是命令行方式,开启session
if (!IS_CLI) {
Session::getInstance()->start(C('SESSION_OPTIONS'));
}
//项目执行
APP::exec();
}
示例12: run
/**
* 运行应用实例 入口文件使用的快捷方法
* @access public
* @return void
*/
public static function run()
{
App::init();
// Session初始化
if (!IS_CLI) {
session(C('SESSION_OPTIONS'));
}
// 记录应用初始化时间
G('initTime');
App::exec();
return;
}
示例13: run
static function run()
{
App::init();
App::route();
try {
$obj = new ReflectionClass(App::$_controller . 'Controller');
$instance = $obj->newInstanceArgs();
$obj->getmethod(App::$_action . 'Action')->invoke($instance);
} catch (Exception $e) {
APP_DEBUG ? exit($e->getMessage()) : APP::log($e->getMessage());
}
}
示例14: run
/**
* 运行控制器
* @access public
* @return void
*/
public static function run()
{
App::init();
//API控制器
if (APP_NAME == 'api') {
App::execApi();
//Widget控制器
} elseif (APP_NAME == 'widget') {
App::execWidget();
//APP控制器
} else {
App::execApp();
}
return;
}
示例15: login
public function login()
{
if ($this->input->post()) {
$username = $this->input->post('username');
$password = $this->input->post('password');
try {
//check if username or email exist on database
$userManager = $this->container->get('user.user_manager');
$user = '';
if ($uname = $userManager->getUserByUsername($username)) {
$user = $uname;
} elseif ($email = $userManager->getUserByEmail($username)) {
$user = $email;
}
// continue if user exists
if ($user) {
if ($user->getStatus() == \user\models\User::STATUS_PENDING) {
throw new Exception("Please click the confirmation link received on your mail to activate the account.");
}
if (!$user->isActive()) {
throw new Exception("Your account has been disabled. Contact administrator.");
}
if (password_verify($password, $user->getPassword())) {
// load permission from file to db
\App::init();
//set user
\App::setUser($user);
$this->session->userId = $user->getId();
$this->session->setFlashMessage('temp', "Welcome! {$user->getUsername()}.<br>Enjoy your session.", 'info');
//check if requested url exists
if ($redirect = $this->session->requestUrl) {
redirect($redirect);
}
redirect(site_url('admin/dashboard'));
}
throw new Exception("Invalid password.");
} else {
throw new Exception("Invalid username or email.");
}
} catch (Exception $e) {
$this->session->setFlashMessage('feedback', $e->getMessage(), 'error');
$this->templateData['username'] = $username;
}
}
$this->templateData['pageTitle'] = 'Login';
$this->templateData['content'] = 'auth/login';
$this->load->view('backend/login_layout', $this->templateData);
}