I was wondering if there was a way to initiate Yii without the MVC pattern. Just load the config, Initiate everything for use in files such as a web service for other customers that would like to communicate with the system without the need to create a new module/controller/action something simple.
Currently my YII index.php file is:
<?php
// Define root directory
defined('ROOT_PATH') or define('ROOT_PATH', dirname(__FILE__) . '/');
// remove the following line when in production mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
// Shortcut for DIRECTORY_SEPERATOR
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
// Load zend auto loader
//require_once "Zend/Loader/Autoloader.php";
//Zend_Loader_Autoloader::getInstance();
// include Yii bootstrap file
require_once(ROOT_PATH.'Library/Yii/yii.php');
// include Init Data
require_once('init.php');
// Set path alias to the library, sources, classes and zend
Yii::setPathOfAlias('library', ROOT_PATH . 'Library');
Yii::setPathOfAlias('sources', ROOT_PATH . 'Library/Sources');
Yii::setPathOfAlias('zend', ROOT_PATH . 'Library/Zend');
Yii::setPathOfAlias('classes', ROOT_PATH . 'Library/Sources/Classes');
// Load Config file
$configFile = ROOT_PATH.'Protected/config/main.php';
// create a Web application instance and run
Yii::createWebApplication($configFile)->run();
exit();
I would like to have something like:
<?php
// Define root directory
defined('ROOT_PATH') or define('ROOT_PATH', dirname(__FILE__) . '/');
// remove the following line when in production mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
// Shortcut for DIRECTORY_SEPERATOR
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
// Load zend auto loader
//require_once "Zend/Loader/Autoloader.php";
//Zend_Loader_Autoloader::getInstance();
// include Yii bootstrap file
require_once(ROOT_PATH.'Library/Yii/yii.php');
// include Init Data
require_once('init.php');
// Set path alias to the library, sources, classes and zend
Yii::setPathOfAlias('library', ROOT_PATH . 'Library');
Yii::setPathOfAlias('sources', ROOT_PATH . 'Library/Sources');
Yii::setPathOfAlias('zend', ROOT_PATH . 'Library/Zend');
Yii::setPathOfAlias('classes', ROOT_PATH . 'Library/Sources/Classes');
// Load Config file
$configFile = ROOT_PATH.'Protected/config/main.php';
// create a Web application instance and run
Yii::createWebApplication($configFile);
// Now i can access everything i have set in the config file such as the db class, caches, and others
print_r(Yii::app()->db->createCommand("something"));
Thanks.