The use of the YII Framework frame Tutorial YIIC Quick Create Yii application Detailed _php example

Source: Internet
Author: User
Tags mkdir php script sqlite svn smarty template yii

The example in this article describes the way the YII framework framework uses YIIC to quickly create yii applications. Share to everyone for your reference, specific as follows:

YII provides powerful command-line tools to quickly create related components and applications. </span>

The CD enters the root directory of the Yii/framework framework.

Perform

# php YIIC
yii Command Runner (based on Yii v1.1.8)
usage:yiic <command-name> [parameters ...]

The following commands are available:
 -message
 -migrate
 -Shell
 -webapp to,

individual command H ELP, use the following:
  YIIC help <command-name>

Can see

Basic command parameter rules for YIIC

YIIC <command-name> [Parameters ...]

Command-name corresponding to have
-Message
-Migrate
-Shell
-WebApp

If you want to see the functionality of a specific command, you can use

YIIC Help <command-name>

For example:

PHP YIIC Shell

1.php Yiic WebApp

Execute PHP YIIC Help WebApp

/* 
USAGE 
 yiic webapp <app-path> 
DESCRIPTION This 
 command generates a YII WEB application at the SP Ecified location. 
PARAMETERS 
 * app-path:required, the directory where the new application would be created. 
  If The directory does not exist, it would be created. After the application 
  are created, please make sure the directory can be accessed by Web users. 
*/ 

Creates a webapp that is based on the complete structure of YII at the specified location. App-path is a storage directory for WebApp. 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/ad Ata/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/l
   Iuyuqiang/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 D/.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 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.

The resulting 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

Look through the browser

http://www.localyii.com/testwebap/

The specific function is said later. Here the use of the command is spoken directly.

2.php YIIC Messag

PHP YIIC help message Print Message command related usage

/* USAGE YIIC message <config-file> DESCRIPTION This command searches for messages to is translated in the SP 
Ecified source files and compiles them into PHP arrays as message source. PARAMETERS * config-file:required, the path of the configuration file. 
  Can find a example in framework/messages/config.php. The file can be placed anywhere and must being 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 extracted messages should is 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 is found in this list to be processed. If empty, all fileswould be processed. -Exclude:array, a list of directory and file exclusions. Each exclusion can is either a name or a path. If a file or directory name or path matches the exclusion, it won't be copied. For example, an exclusion of '. SVN ' would exclude all files and directories whose name is '. SVN '. 
  and an exclusion of '/a/b ' to 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 is overwritten with the merged messages. 

 */

Mainly for the internationalization of WebApp.

For example, the TESTWEBAP produced above
Http://www.localyii.com/testwebap/index.php?r=site/login

Login page username and password translated into Chinese

It says that you need a configuration file. Yii provides us with templates for configuration files.

framework/messages/config.php

Copy framework\messages\config.php file to Protected\messages\

The specific content is modified 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

Modified 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 ');?>

Execute 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 ' => ',
);

To

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 is accessed
//Using Yii::app ()->params[' paramname ']
' params ' = >array (
//) used in the contact page
' adminemail ' => ' webmaster@example.com ',
),
' Language ' => ' zh_cn ',
' sourcelanguage ' => ' en_US ',
);

Visit a bit

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

You can see the translation into Chinese.

Can have garbled problem, pay attention to coding problems. file, browser to set the unified

More about Yii related content readers can view the site topics: "Yii framework Introduction and common skills Summary", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming Program", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design based on the YII framework.

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.