YII 系统命令行生成代码

使用YII框架创建控制器
本文介绍了如何在YII框架中使用命令行界面创建控制器、模型、CURD操作和模块,详细展示了创建过程和相关命令的使用方法。

1.cmd输入(已经加入YII framework到环境变量)

yiic shell "E:\Apache2\htdocs\test\index.php"

 或

E:\Apache2\htdocs\test\protected>yiic shell "E:\Apache2\htdocs\test\index.php"

 SHELL代码或屏幕回显

Yii Interactive Tool v1.1
Please type 'help' for help. Type 'exit' to quit.

你当前显示的是与shell交互的提示符。你可以输入help查看shell为你提供的所有命令列表

>> help
At the prompt, you may enter a PHP statement or one of the following commands:
 - controller
 - crud
 - form
 - help
 - model
 - module
Type 'help <command-name>' for details about a command. 

 我们看了有几个可选的命令,有一个controller命令看起来象是我们想要的,可能是用来为应用程序创建一个控制器的命令。我们可以在shell提标符下进一步了解controller命令的更多帮助信息。这些信息包括提供的用法说明,参数描述和一些例子。

>> help controller
USAGE
    controller <controller-ID> [action-ID] ...
 
DESCRIPTION
    This command generates a controller and views associated with the specified actions.
 
PARAMETERS
  * controller-ID: required, controller ID, e.g., 'post'.
     If the controller should be located under a subdirectory, 
     please specify the controller ID as 'path/to/ControllerID',
     e.g., 'admin/user'.
 
     If the controller belongs to a module, please specify 
     the controller ID as 'ModuleID/ControllerID' or 
     'ModuleID/path/to/Controller' (assuming the controller is under a subdirectory of that module).
 
  * action-ID: optional, action ID. You may supply one or several action IDs. 
     A default 'index' action will always be generated.
 
EXAMPLES
  * Generates the 'post' controller:
            controller post
 
  * Generates the 'post' controller with additional actions 'contact' and 'about':
            controller post contact about 
 
  * Generates the 'post' controller which should be located under
    the 'admin' subdirectory of the base controller path:
            controller admin/post
 
  * Generates the 'post' controller which should belong to the 'admin' module:
            controller admin/post

 阅读帮助,很明显看出该命令会生成控制器和操作方法及视图文件。由于我们将要做的应用程序主要是显示一条消息,让我们调用controller message 和一个要显示的操作方法:

>> controller message helloWorld
generate MessageController.php
               mkdir /Webroot/demo/protected/views/message
        generate helloworld.php
        generate index.php
 
Controller 'message' has been created in the following file: 
        /Webroot/demo/protected/controllers/MessageController.php
 
You may access it in the browser using the following URL: 
        http://hostname/path/to/index.php?r=message
>>

 1.model

>> model User tbl_user
   generate models/User.php
   generate fixtures/tbl_user.php
   generate unit/UserTest.php

The following model classes are successfully generated:
    User

If you have a 'db' database connection, you can test these models now with:
    $model=User::model()->find();
    print_r($model);

 2. CURD

>> crud User
   generate UserController.php
   generate UserTest.php
   mkdir D:/testdrive/protected/views/user
   generate create.php
   generate update.php
   generate index.php
   generate view.php
   generate admin.php
   generate _form.php
   generate _view.php

Crud 'user' has been successfully created. You may access it via:

 3.module

>> module wiki
      mkdir E:/Apache2/htdocs/webapp/protected/modules
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki/components
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki/controllers
   generate controllers/DefaultController.php
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki/messages
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki/models
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki/views
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki/views/default
   generate views/default/index.php
      mkdir E:/Apache2/htdocs/webapp/protected/modules/wiki/views/layouts
   generate WikiModule.php

Module 'wiki' has been created under the following folder:
    E:\Apache2\htdocs\webapp\protected\modules\wiki

You may access it in the browser using the following URL:
    http://hostname/path/to/index.php?r=wiki

Note, the module needs to be installed first by adding 'wiki'
to the 'modules' property in the application configuration.

 4.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值