YIIFramework framework Tutorial: Using YIIC to quickly create YII application detail_php instance

Source: Internet
Author: User
This article describes how to quickly create an YII application using YIIFramework framework in the YIIFramework framework tutorial. A detailed analysis shows the skills and precautions for the YIIFramework framework to create an application using YIIC command lines, for more information about how to quickly create a YII application using YIIC, see the example in this article. We will share this with you for your reference. The details are as follows:

Yii provides powerful command line tools to quickly create related components and applications.

Cd to enter the root directory of the yii/framework.

Run

# php yiicYii command runner (based on Yii v1.1.8)Usage: yiic 
 
   [parameters...]The following commands are available: - message - migrate - shell - webappTo see inpidual command help, use the following:  yiic help 
  
 

We can see that

Basic command parameter rules of yiic

Yiic [Parameters...]

Command-name corresponds
-Message
-Migrate
-Shell
-Webapp

You can use

Yiic help

For example:

php yiic shell

1. php yiic webapp

Execute php yiic help webapp

/* USAGE  yiic webapp  DESCRIPTION  This command generates an Yii Web Application at the specified location. PARAMETERS  * app-path: required, the directory where the new application will be created.   If the directory does not exist, it will be created. After the application   is created, please make sure the directory can be accessed by Web users. */ 

Create a full yii-based webapp at the specified location. App-path is the directory where webapp is stored. If the directory does not exist, it will be created.

For example:

/yii/framework# php yiic webapp ../../testwebap Create a Web application under '/home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap'? [Yes|No] Yes   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap  generate index-test.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/themes   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/themes/classic   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/themes/classic/views   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/themes/classic/views/layouts  generate themes/classic/views/.htaccess   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/themes/classic/views/site   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/themes/classic/views/system   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/css  generate css/ie.css  generate css/bg.gif  generate css/screen.css  generate css/form.css  generate css/print.css  generate css/main.css  generate index.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/assets   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/models  generate protected/models/LoginForm.php  generate protected/models/ContactForm.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/components  generate protected/components/UserIdentity.php  generate protected/components/Controller.php  generate protected/yiic.bat   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/controllers  generate protected/controllers/SiteController.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/migrations  generate protected/yiic   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/data  generate protected/data/testdrive.db  generate protected/data/schema.mysql.sql  generate protected/data/schema.sqlite.sql   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/config  generate protected/config/test.php  generate protected/config/console.php  generate protected/config/main.php  generate protected/.htaccess   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/layouts  generate protected/views/layouts/column1.php  generate protected/views/layouts/column2.php  generate protected/views/layouts/main.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/site  generate protected/views/site/contact.php  generate protected/views/site/login.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/site/pages  generate protected/views/site/pages/about.php  generate protected/views/site/index.php  generate protected/views/site/error.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/messages   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests  generate protected/tests/bootstrap.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests/fixtures  generate protected/tests/phpunit.xml   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests/report   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests/unit   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests/functional  generate protected/tests/functional/SiteTest.php  generate protected/tests/WebTestCase.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/runtime  generate protected/yiic.php   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/extensions   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/commands   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/commands/shell   mkdir /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/images

Your application has been created successfully under/yii_dev/testwebap.

The generated directory structure is as follows:

Testwebap
│ ── Assets
│ ── Css
│ ── Images
│ ── Index. php
│ ── Index-test.php.
│ ── Protected
│ ── Themes
The detailed directory structure is as follows:
── Assets
├ ── Css
│ ── Bg.gif
│ ── Form.css
│ ── Ie.css
│ ── Main.css
│ ── Print.css
│ ── Screen.css
── Images
── Index. php
── Index-test.php
├ ── Protected
│ ── Commands
│ ── Shell
│ ── Components
│ ── Controller. php
│ ── UserIdentity. php
│ ── Config
│ ── Console. php
│ ── Main. php
│ └ ── Test. php
│ ── Controllers
│ ── SiteController. php
│ ── Data
│ ── Schema. mysql. SQL
│ ── Schema. sqlite. SQL
│ ── Testdrive. db
│ ── Extensions
│ ── Messages
│ ── Migrations
│ ── Models
│ ├ ── ContactForm. php
│ ── LoginForm. php
│ ── Runtime
│ ── Tests
│ ── Bootstrap. php
│ ── Fixtures
│ ── Functional
│ ── SiteTest. php
│ ── Phpunit. xml
│ ── Report
│ ── Unit
│ ── WebTestCase. php
│ ── Views
│ ── Layouts
│ ── Column1.php
│ ── Column2.php
│ ── Main. php
│ ── Site
│ ── Contact. php
│ ── Error. php
│ ── Index. php
│ ── Login. php
│ ── Pages
│ ── About. php
│ ── Yiic
│ ── Yiic. bat
│ ── Yiic. php
── Themes
── Classic
── Views
── Layouts
── Site
── System

Check in the browser

Http://www.localyii.com/testwebap/

The specific functions are described later. Here we will talk about the use of commands.

2. php yiic mescript

Php yiic help message: usage of the message command

/* USAGE  yiic message 
 
   DESCRIPTION  This command searches for messages to be translated in the specified  source files and compiles them into PHP arrays as message source. PARAMETERS  * config-file: required, the path of the configuration file. You can find   an example in framework/messages/config.php.   The file can be placed anywhere and must be a valid PHP script which   returns an array of name-value pairs. Each name-value pair represents   a configuration option.   The following options are available:   - sourcePath: string, root directory of all source files.   - messagePath: string, root directory containing message translations.   - languages: array, list of language codes that the extracted messages    should be translated to. For example, array('zh_cn','en_au').   - fileTypes: array, a list of file extensions (e.g. 'php', 'xml').    Only the files whose extension name can be found in this list    will be processed. If empty, all files will be processed.   - exclude: array, a list of directory and file exclusions. Each    exclusion can be either a name or a path. If a file or directory name    or path matches the exclusion, it will not be copied. For example,    an exclusion of '.svn' will exclude all files and directories whose    name is '.svn'. And an exclusion of '/a/b' will exclude file or    directory 'sourcePath/a/b'.   - translator: the name of the function for translating messages.    Defaults to 'Yii::t'. This is used as a mark to find messages to be    translated.   - overwrite: if message file must be overwritten with the merged messages. */ 
 

It is mainly used for internationalization of webapps.

For example
Http://www.localyii.com/testwebap/index.php? R = site/login

The Username and Password on the logon page are translated into Chinese.

The configuration file is required. Yii provides us with a configuration file template.

Framework/messages/config. php

Copy the framework \ messages \ config. php file to protected \ messages \.

Modify the content as follows:

dirname(__FILE__).DIRECTORY_SEPARATOR.'..',   'messagePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'messages',   'languages'=>array('zh_cn'),   'fileTypes'=>array('php'),   'overwrite'=>true,   'exclude'=>array(     '.svn',     'yiilite.php',     'yiit.php',     '/i18n/data',     '/messages',     '/vendors',     '/web/js',   ), ); 

/Www/yii_dev/testwebap/protected/views/site/login. php

Modify as follows:

labelEx($model,Yii::t('login_message','username')); ?>textField($model,'username'); ?>error($model,'username'); ?>labelEx($model,Yii::t('login_message','password')); ?>passwordField($model,'password'); ?>error($model,'password'); ?>

Run the following command:

testwebap/protected/messages/www/yii_dev/yii/framework# php yiic message "../../testwebap/protected/messages/config.php"Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/components/Controller.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/components/UserIdentity.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/config/console.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/config/main.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/config/test.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/controllers/SiteController.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/models/ContactForm.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/models/LoginForm.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests/WebTestCase.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests/bootstrap.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/tests/functional/SiteTest.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/layouts/column1.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/layouts/column2.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/layouts/main.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/site/contact.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/site/error.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/site/index.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/site/login.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/views/site/pages/about.php...Extracting messages from /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/yiic.php...Saving messages to /home/coder/adata/liuyuqiang/wamp/www/yii_dev/testwebap/protected/messages/../messages/zh_cn/login_message.php...saved.

Directory to generate the following files

/Www/yii_dev/testwebap/protected/messages/zh_cn/login_message.php

return array ('password' => '','username' => '',);

Change

Return array ('Password' => 'Password', 'username' => 'username ',);

Modify

The following configuration file

/Www/yii_dev/testwebap/protected/config/main. php

Add the following

// application-level parameters that can be accessed// using Yii::app()->params['paramName']'params'=>array(// this is used in contact page'adminEmail'=>'webmaster@example.com',),'language'=>'zh_cn','sourceLanguage'=>'en_us',);

One-to-one access

Http://www.localyii.com/testwebap/index.php? R = site/login

You can see that it is translated into Chinese.

There may be garbled characters. Pay attention to coding. File, the browser should be set to uniform

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.