热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

YIIFramework框架教程之使用YIIC快速创建YII应用详解_php实例

这篇文章主要介绍了YIIFramework框架教程之使用YIIC快速创建YII应用的方法,详细分析说明了YIIFramework框架使用YIIC命令行创建应用的相关技巧与注意事项,需要的朋友可以参考下
本文实例讲述了YII Framework框架使用YIIC快速创建YII应用的方法。分享给大家供大家参考,具体如下:

yii提供了强大的命令行工具来快速的创建相关组件和应用。

cd进入yii/framework框架的根目录。

执行

# php yiic
Yii command runner (based on Yii v1.1.8)
Usage: yiic  [parameters...]

The following commands are available:
 - message
 - migrate
 - shell
 - webapp

To see inpidual command help, use the following:
  yiic help 

可以看到

yiic的基本命令参数规则

yiic [parameters...]

command-name对应的有
- message
- migrate
- shell
- webapp

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

yiic help

例如:

php yiic shell

1.php yiic webapp

执行 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. 
*/ 

在指定的位置创建一个基于yii的完整结构的webapp。app-path是webapp的存放目录。如果目录不存在会被创建。

例如:

/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命令的相关用法

/* 
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. 
*/ 

主要用于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\下

具体内容修改如下:

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

修改如下

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

执行如下命令

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

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

改为

return array (
'password' => '密码',
'username' => '用户名',
);

修改

如下配置文件

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

添加如下

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

访问一一下

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

可以看到翻译成中文了。

可以有乱码的问题,注意编码问题。文件,浏览器要设置统一

更多关于Yii相关内容感兴趣的读者可查看本站专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

推荐阅读
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文由编程笔记小编整理,介绍了PHP中的MySQL函数库及其常用函数,包括mysql_connect、mysql_error、mysql_select_db、mysql_query、mysql_affected_row、mysql_close等。希望对读者有一定的参考价值。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 如何在php中将mysql查询结果赋值给变量
    本文介绍了在php中将mysql查询结果赋值给变量的方法,包括从mysql表中查询count(学号)并赋值给一个变量,以及如何将sql中查询单条结果赋值给php页面的一个变量。同时还讨论了php调用mysql查询结果到变量的方法,并提供了示例代码。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文介绍了前端人员必须知道的三个问题,即前端都做哪些事、前端都需要哪些技术,以及前端的发展阶段。初级阶段包括HTML、CSS、JavaScript和jQuery的基础知识。进阶阶段涵盖了面向对象编程、响应式设计、Ajax、HTML5等新兴技术。高级阶段包括架构基础、模块化开发、预编译和前沿规范等内容。此外,还介绍了一些后端服务,如Node.js。 ... [详细]
  • 基于SpringBoot打造在线教育系统(6)– 二级分类模块UI篇
    这一节来做二级分类,为了快速开发,一级分类只做新增,暂时不考虑修改和删除,如果一定要删,就去数据库删吧。我们接下来,需要通过一级分类,获取所有的二级分类。开始 ... [详细]
  • 1、DashAPI文档Dash是一个API文档浏览器,使用户可以使用离线功能即时搜索无数API。程序员使用Dash可访问iOS,MacOS, ... [详细]
  • 视图分区_组复制常规操作网络分区amp;混合使用IPV6与IPV4 | 全方位认识 MySQL 8.0 Group Replication...
    网络分区对于常规事务而言,每当组内有事务数据需要被复制时,组内的成员需要达成共识(要么都提交,要么都回滚)。对于组成员资格的变更也和保持组 ... [详细]
author-avatar
caozhengweile_854
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有