本文整理汇总了PHP中Yii::createWebApplication方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::createWebApplication方法的具体用法?PHP Yii::createWebApplication怎么用?PHP Yii::createWebApplication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::createWebApplication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @param $root
* @param string $configName
* @param mixed $mergeWith
* @return mixed
* @throws Exception
*/
public static function create($root, $configName = 'main', $mergeWith = array('common', 'env'))
{
if (($root = realpath($root)) === false) {
throw new Exception('could not initialize framework.');
}
$config = self::config($configName, $mergeWith);
$class = Config::value('yiinitializr.app.classes.' . $configName);
if ($class && !is_callable($class)) {
throw new Exception('yiinitializr.app.classes.' . $configName . ' class must be callable.');
}
if (php_sapi_name() !== 'cli') {
// aren't we in console?
$app = $class ? $class($config) : \Yii::createWebApplication($config);
} else {
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
$app = $class ? $class($config) : \Yii::createConsoleApplication($config);
$app->commandRunner->addCommands($root . '/cli/commands');
$env = @getenv('YII_CONSOLE_COMMANDS');
if (!empty($env)) {
$app->commandRunner->addCommands($env);
}
}
// return an app
return $app;
}
示例2: setUp
/**
* set up environment with yii application and migrate up db
*/
public function setUp()
{
$basePath = dirname(__FILE__) . '/tmp';
if (!file_exists($basePath)) {
mkdir($basePath, 0777, true);
}
if (!file_exists($basePath . '/runtime')) {
mkdir($basePath . '/runtime', 0777, true);
}
// create webapp
if (\Yii::app() === null) {
\Yii::createWebApplication(array('basePath' => $basePath));
}
\CActiveRecord::$db = null;
if (!isset($_ENV['DB']) || $_ENV['DB'] == 'sqlite') {
if (!$this->dbFile) {
$this->dbFile = $basePath . '/test.' . uniqid(time()) . '.db';
}
\Yii::app()->setComponent('db', new \CDbConnection('sqlite:' . $this->dbFile));
} elseif ($_ENV['DB'] == 'mysql') {
\Yii::app()->setComponent('db', new \CDbConnection('mysql:dbname=test;host=localhost', 'root'));
} elseif ($_ENV['DB'] == 'pgsql') {
\Yii::app()->setComponent('db', new \CDbConnection('pqsql:dbname=test;host=localhost', 'postgres'));
} else {
throw new \Exception('Unknown db. Only sqlite, mysql and pgsql are valid.');
}
// create db
$this->migration = new EActiveRecordRelationBehaviorTestMigration();
$this->migration->dbConnection = \Yii::app()->db;
$this->migration->up();
}
示例3: actionClearFrontend
public function actionClearFrontend()
{
$local = (require './protected/config/main-local.php');
$base = (require './protected/config/main.php');
$config = CMap::mergeArray($base, $local);
Yii::setApplication(null);
Yii::createWebApplication($config)->cache->flush();
$this->redirect('index');
}
示例4: init
/**
* Executa as operações de inicialização.
*/
public static final function init()
{
self::defineConstants();
self::includeFrameworkLib();
self::checkExtraConfigFiles();
// Inicializa
$config = APP_ROOT . '/configs/mainConfig.php';
if (!is_readable($config)) {
self::initError('O arquivo de configurações está inacessível.');
} else {
Yii::createWebApplication($config)->run();
}
}
示例5: run
/**
* Execute the action.
* @param array $args command line parameters specific for this command
*/
public function run($args)
{
if (!isset($args[0])) {
$args[0] = 'index.php';
}
$entryScript = isset($args[0]) ? $args[0] : 'index.php';
if (($entryScript = realpath($args[0])) === false || !is_file($entryScript)) {
$this->usageError("{$args[0]} does not exist or is not an entry script file.");
}
// fake the web server setting
$cwd = getcwd();
chdir(dirname($entryScript));
$_SERVER['SCRIPT_NAME'] = '/' . basename($entryScript);
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'] = $entryScript;
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 80;
// reset context to run the web application
restore_error_handler();
restore_exception_handler();
Yii::setApplication(null);
Yii::setPathOfAlias('application', null);
ob_start();
$config = (require $entryScript);
ob_end_clean();
// oops, the entry script turns out to be a config file
if (is_array($config)) {
chdir($cwd);
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'] = $cwd . DIRECTORY_SEPARATOR . 'index.php';
Yii::createWebApplication($config);
}
restore_error_handler();
restore_exception_handler();
$yiiVersion = Yii::getVersion();
echo <<<EOD
Yii Interactive Tool v1.1 (based on Yii v{$yiiVersion})
Please type 'help' for help. Type 'exit' to quit.
EOD;
$this->runShell();
}
示例6: __construct
public function __construct()
{
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set(array('worker_num' => 10, 'daemonize' => false, 'max_request' => 10000, 'dispatch_mode' => 1));
$http->on('WorkerStart', array($this, 'onWorkerStart'));
$http->on('request', function ($request, $response) {
if (isset($request->server)) {
HttpServer::$server = $request->server;
foreach ($request->server as $key => $value) {
$_SERVER[strtoupper($key)] = $value;
}
}
if (isset($request->header)) {
HttpServer::$header = $request->header;
}
if (isset($request->get)) {
HttpServer::$get = $request->get;
foreach ($request->get as $key => $value) {
$_GET[$key] = $value;
}
}
if (isset($request->post)) {
HttpServer::$post = $request->post;
foreach ($request->post as $key => $value) {
$_POST[$key] = $value;
}
}
ob_start();
//实例化yii对象
try {
$this->application = Yii::createWebApplication(FRAMEWORK_CONFIG);
$this->application->run();
} catch (Exception $e) {
var_dump($e);
}
$result = ob_get_contents();
ob_end_clean();
$response->end($result);
unset($result);
unset($this->application);
});
$http->start();
}
示例7: setUp
/**
* set up environment with yii application and migrate up db
*/
public function setUp()
{
$basePath = dirname(__FILE__) . '/tmp';
if (!file_exists($basePath)) {
mkdir($basePath, 0777, true);
}
if (!file_exists($basePath . '/runtime')) {
mkdir($basePath . '/runtime', 0777, true);
}
if (!$this->db) {
$this->db = $basePath . '/test.' . uniqid(time()) . '.db';
}
// create webapp
if (\Yii::app() === null) {
\Yii::createWebApplication(array('basePath' => $basePath));
}
\CActiveRecord::$db = null;
\Yii::app()->setComponent('db', new \CDbConnection('sqlite:' . $this->db));
// create db
$this->migration = new EActiveRecordRelationBehaviorTestMigration();
$this->migration->dbConnection = \Yii::app()->db;
$this->migration->up();
}
示例8: dirname
<?php
// change the following paths if necessary
$yii = dirname(__FILE__) . '/../yiiframework/yii-1.1.14.f0fee9/framework/yii.php';
$config = dirname(__FILE__) . '/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
require_once $yii;
Yii::createWebApplication($config)->run();
示例9: dirname
<?php
$webRoot = dirname(__FILE__);
// Если хост равен localhost, то включаем режим отладки и подключаем отладочную
// конфигурацию
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
define('YII_DEBUG', true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
require_once $webRoot . '/yii/framework/yii.php';
$configFile = $webRoot . '/protected/config/dev.php';
} else {
error_reporting(E_ALL & ~E_NOTICE);
define('YII_DEBUG', true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
require_once $webRoot . '/yii/framework/yiilite.php';
$configFile = $webRoot . '/protected/config/production.php';
}
$app = Yii::createWebApplication($configFile)->run();
示例10: date_default_timezone_set
<?php
/**
* Входной скрипт index:
*
* @category YupeScript
* @package YupeCMS
* @author Yupe Team <team@yupe.ru>
* @license https://github.com/yupe/yupe/blob/master/LICENSE BSD
* @link http://yupe.ru
**/
// подробнее про index.php http://www.yiiframework.ru/doc/guide/ru/basics.entry
if (!ini_get('date.timezone')) {
date_default_timezone_set('Europe/Moscow');
}
// Setting internal encoding to UTF-8.
if (!ini_get('mbstring.internal_encoding')) {
@ini_set("mbstring.internal_encoding", 'UTF-8');
mb_internal_encoding('UTF-8');
}
// две строки закомментировать на продакшн сервере
define('YII_DEBUG', true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
require __DIR__ . '/../vendor/yiisoft/yii/framework/yii.php';
$base = (require __DIR__ . '/../protected/config/main.php');
$confManager = new yupe\components\ConfigManager();
$confManager->sentEnv(\yupe\components\ConfigManager::ENV_WEB);
require __DIR__ . '/../vendor/autoload.php';
Yii::createWebApplication($confManager->merge($base))->run();
示例11: define
<?php
/**
* Test Web Entry Script
*
* @author Brett O'Donnell <cornernote@gmail.com>
* @author Zain Ul abidin <zainengineer@gmail.com>
* @copyright 2013 Mr PHP
* @link https://github.com/cornernote/yii-email-module
* @license BSD-3-Clause https://raw.github.com/cornernote/yii-email-module/master/LICENSE
*
* @package yii-email-module
*/
// define paths
define('BASE_PATH', realpath(__DIR__ . '/..'));
define('VENDOR_PATH', realpath(BASE_PATH . '/../vendor'));
define('YII_PATH', realpath(VENDOR_PATH . '/yiisoft/yii/framework'));
// debug
define('YII_DEBUG', true);
// composer autoloader
require_once VENDOR_PATH . '/autoload.php';
// create application
require_once YII_PATH . '/yii.php';
Yii::createWebApplication(BASE_PATH . '/_config.php')->run();
示例12:
<?php
require_once 'define.php';
$config = ROOT_PATH . '/protected/config/fontend.php';
// create a Web application instance and run
Yii::createWebApplication($config)->runEnd('fontend');
示例13: header
<?php
header("Content-Type: text/html; charset=UTF-8");
if ($_COOKIE['YII_DEBUG'] === "true") {
// Подключение параметров для режима отладки
$yii = dirname(__FILE__) . '/../framework/yii.php';
$CONFIG = dirname(__FILE__) . '/protected/config/main_dev.php';
//Настройка вывода сообщений
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", 1);
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
} else {
// Подключение стандартных параметров
$yii = dirname(__FILE__) . '/framework/yii.php';
$CONFIG = dirname(__FILE__) . '/protected/config/main.php';
// Отключение вывода сообщений
error_reporting(E_WARNING);
ini_set("display_errors", 0);
}
require_once $yii;
Yii::createWebApplication($CONFIG)->run();
示例14: error_reporting
<?php
error_reporting(E_ALL | E_STRICT);
require dirname(__FILE__) . '/../../../../../framework/yiit.php';
require dirname(__FILE__) . '/ResultPrinter.php';
Yii::createWebApplication(require dirname(__FILE__) . '/../../../config/main.php');
示例15: dirname
//директория ядра фреймворка
$frameworkFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'YiiBase.php';
//проверяем существование локального конфига
$localConfigFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.php';
file_exists($localConfigFile) && is_readable($localConfigFile) or die('Local config file not exist');
//основной конфиг
$mainConfigFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
//определяем необходимо ли включать режим дебага или нет. Включить можно перегрузив в local.php директиву params[debugMode]
if (($localConfigFileInclude = (require $localConfigFile)) && isset($localConfigFileInclude['params']['debugMode'])) {
//подключение режима DEBUG для ловли ошибок и исключений
defined('YII_DEBUG') or define('YII_DEBUG', true);
//константа уровня трассировки
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', isset($localConfigFileInclude['params']['debugTraceLevel']) ? $localConfigFileInclude['params']['debugTraceLevel'] : 3);
}
//подключаем ядро фреймворка
require_once $frameworkFile;
//небольшой хак для автокомплита в шторме
class Yii extends YiiBase
{
/**
* @static
* @return MyCWebApplication
*/
public static function app()
{
return parent::app();
}
}
//создаем веб-приложение и запускаем его
Yii::createWebApplication($mainConfigFile)->run();