yii2.0 command to act as a combat

Source: Internet
Author: User

1. Add Yii and Yii.bat two files under the root directory

Where Yii content is as follows

#!/usr/bin/env PHP

<?php

/**

* YII Console bootstrap file.

*

* @link http://www.yiiframework.com/

* @copyright Copyright (c) Yii software LLC

* @license http://www.yiiframework.com/license/

*/


Defined (' Yii_debug ') or define (' Yii_debug ', true);


fcgi doesn ' t has STDIN and STDOUT defined by default

Defined (' STDIN ') or define (' STDIN ', fopen (' Php://stdin ', ' r '));

Defined (' STDOUT ') or define (' STDOUT ', fopen (' Php://stdout ', ' W '));


Require (__dir__. '/vendor/autoload.php ');

Require (__dir__. '/vendor/yiisoft/yii2/yii.php ');

Require (__dir__. '/common/bootstrap.php '); Load alias Configuration

$config = require (__dir__. '/config/console.php ');


$application = new Yii\console\application ($config);

$exitCode = $application->run ();

Exit ($exitCode);

The contents of Yii.bat are as follows

@echo off


REM-------------------------------------------------------------

REM Yii command line bootstrap script for Windows.

Rem

REM @author Qiang Xue <[email protected]>

REM @link http://www.yiiframework.com/

REM @copyright Copyright (c) Yii software LLC

REM @license http://www.yiiframework.com/license/

REM-------------------------------------------------------------


@setlocal


Set Yii_path=%~dp0


If "%php_command%" = = "" Set Php_command=d:\wamp\bin\php\php5.4.16\php.exe (the main change is the location of this PHP)


"%php_command%" "%yii_path%yii"%*


@endlocal


The contents of common/bootstrap.php are as follows

<?php

Defining aliases

Yii::setalias (' Modules ', dirname (__dir__). ' \modules ');

The contents of which config/console.php are as follows

<?php


Yii::setalias (' @tests ', DirName (__dir__). '/tests ');


$params = require (__dir__. '/params.php ');


return [

' id ' = ' basic-console ',

' BasePath ' = dirname (__dir__),

' Bootstrap ' = [' log '],

' Controllernamespace ' = ' app\commands ',

' Components ' = [

' Filecache ' = [

' Class ' = ' Yii\caching\filecache ',

],

' Log ' = [

' Targets ' = [

[

' Class ' = ' Yii\log\filetarget ',

' Levels ' = [' Error ', ' warning '],

],

],

],

' db ' = [

' Class ' = ' yii\db\connection ',

' DSN ' = ' mysql:host=localhost;dbname=test ',

' Emulateprepare ' = true,

' Enableprofiling ' = true,

' Enableparamlogging ' = False,

' Username ' = ' test ',

' Password ' = ' Test ',

' CharSet ' = ' utf8 ',

' Tableprefix ' = ' test_ ',

],

],

' Modules ' = [

' Examples ' = [

' Class ' = ' Modules\examples\index ',

' db ' = ' db ',

],

],

' Params ' = $params,

];

Which configures the key filecache in the components, when used such yii:: $app->filecache->get ("test");

Where the DB is called when this \yii:: $app->db->createcommand ()->insert ($this->tablename, $data)->execute ();

The bottom modules module is the load module in the commands inside the controller use when used or will error: Class "Modules\test\models\test" not Found

' Modules ' = [

' Examples ' = [

' Class ' = ' Modules\examples\index ',

' db ' = ' db ',

],

],



2. Open windows command line cmd

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5B/6A/wKioL1UI8sGCvBSJAAG-BGgs8KE656.jpg "title=" Zy1}e6 {) _1~_{@KYJXN}1xn.png "alt=" Wkiol1ui8sgcvbsjaag-bggs8ke656.jpg "/>

3, start to write a test controller under the commands directory content as follows



650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5B/70/wKiom1UI8lTgjKtWAAVrTSFbEIc623.jpg "title=" l]{}] GOTGHRH (c5[mtqqgoo.png "alt=" Wkiom1ui8ltgjktwaavrtsfbeic623.jpg "/>



yii2.0 command to act as a combat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.