一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - YII Framework框架教程之使用YIIC快速創建YII應用詳解

YII Framework框架教程之使用YIIC快速創建YII應用詳解

2020-12-29 16:38coder PHP教程

這篇文章主要介紹了YII Framework框架教程之使用YIIC快速創建YII應用的方法,詳細分析說明了YII Framework框架使用YIIC命令行創建應用的相關技巧與注意事項,需要的朋友可以參考下

本文實例講述了YII Framework框架使用YIIC快速創建YII應用的方法。分享給大家供大家參考,具體如下:

yii提供了強大的命令行工具來快速的創建相關組件和應用。</span> 

cd進入yii/framework框架的根目錄。

執行

?
1
2
3
4
5
6
7
8
9
10
11
12
# 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 see individual command help, use the following:
  yiic help <command-name>

可以看到

yiic的基本命令參數規則

yiic <command-name> [parameters...]

command-name對應的有
 - message
 - migrate
 - shell
 - webapp

如果要查看具體的命令的功能可以用

yiic help <command-name>

例如:

?
1
php yiic shell

1.php yiic webapp

執行 php yiic help webapp

?
1
2
3
4
5
6
7
8
9
10
/*
USAGE
 yiic webapp <app-path>
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.
*/

在指定的位置創建一個基于yii的完整結構的webapp。app-path是webapp的存放目錄。如果目錄不存在會被創建。

例如:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/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.

生成的目錄結構如下

testwebap
│   ├── assets
│   ├── css
│   ├── images
│   ├── index.php
│   ├── index-test.php
│   ├── protected
│   └── themes
詳細目錄結構如下
├── 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

通過瀏覽器查看一下

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

具體功能后面講。這里直接講命令的使用。

2.php yiic messag

php yiic help message打印message命令的相關用法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
USAGE
 yiic message <config-file>
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.
*/

主要用于webapp的國際化。

例如將上面生產的testwebap的
http://www.localyii.com/testwebap/index.php?r=site/login

登錄頁面的Username和Password   翻譯成中文

上面說需要配置文件。yii為我們提供了配置文件的模板。

framework/messages/config.php

復制framework\messages\config.php 文件到 protected\messages\下

具體內容修改如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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

修改如下

?
1
2
3
4
5
6
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'); ?>

執行如下命令

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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.

目錄下生成如下文件

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

?
1
2
3
4
return array (
'password' => '',
'username' => '',
);

改為

?
1
2
3
4
return array (
'password' => '密碼',
'username' => '用戶名',
);

修改

如下配置文件

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

添加如下

?
1
2
3
4
5
6
7
8
9
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'[email protected]',
),
'language'=>'zh_cn',
'sourceLanguage'=>'en_us',
);

訪問一一下

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

可以看到翻譯成中文了。

可以有亂碼的問題,注意編碼問題。文件,瀏覽器要設置統一

希望本文所述對大家基于Yii框架的PHP程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: yellow片在线观看 | 免费观看小视频 | 海派甜心完整版在线观看 | 91在线一区二区三区 | 日产乱码卡1卡2卡三卡四在线 | 国产农村乱子伦精品视频 | 日本在线www | 免费370理论片中文字幕 | 91精品手机国产露脸 | 9999视频 | 亚洲可乐操 | 草莓视频旧版 | 欧美日韩亚洲综合在线一区二区 | 暖暖日本高清 | 91你懂的| 赤坂丽女医bd无删减在线观看 | 免费刷10000名片赞网站 | 好大用力深一点视频 | 午夜精品久久久久久久99 | 舔穴吸奶 | 精品91自产拍在线观看99re | 欧美激烈精交gif动态图18p | 欧美成人另类人妖 | 日本成熟bbxxxxxxxx | 九九精品免视频国产成人 | 俄罗斯妈妈k8影院在线观看 | 满溢游泳池免费 | 全日爱韩国视频在线观看 | 女人和男人搞基 | 红楼梦黄色小说 | 国产精品成人麻豆专区 | 免费被黄网站在观看 | 99久久99热久久精品免费看 | 超级乱淫伦短篇在车上 | 秋霞啪啪网 | 白丝出水 | bt7086新片速递亚洲最新合集 | 精品综合久久久久久8888 | 亚洲国产精品高清在线 | 奇米色88欧美一区二区 | 女仆色网址 |