// Require the Yii framework autoload file require_once __DIR__ . '/vendor/autoload.php'; // Create a new Yii application instance $app = Yii::createApplication('yii\\web\\Application', [ 'id' => 'my-app', 'basePath' => __DIR__, 'components' => [ 'db' => [ 'class' => 'yii\\db\\Connection', 'dsn' => 'mysql:host=localhost;dbname=my_database', 'username' => 'root', 'password' => '', ], ], ]); // Run the application $app->run();
// Require the Yii framework autoload file require_once __DIR__ . '/vendor/autoload.php'; // Create a new Yii console application instance $app = Yii::createApplication('yii\\console\\Application', [ 'id' => 'my-console-app', 'basePath' => __DIR__, 'controllerNamespace' => 'app\\commands', ]); // Run the console application $app->run();
// Require the Yii framework autoload file require_once __DIR__ . '/vendor/autoload.php'; // Create a new Yii application instance $app = Yii::createApplication('yii\\web\\Application', [ 'id' => 'my-mvc-app', 'basePath' => __DIR__, 'components' => [ 'db' => [ 'class' => 'yii\\db\\Connection', 'dsn' => 'mysql:host=localhost;dbname=my_database', 'username' => 'root', 'password' => '', ], ], ]); // Define the application routes $app->urlManager->addRules([ '/' => 'site/index', 'about' => 'site/about', 'contact' => 'site/contact', ]); // Run the application $app->run();In this example, we create a basic Yii MVC web application with a database connection and custom application routes. Package: Yii framework