<bdo id='ts6Wh'></bdo><ul id='ts6Wh'></ul>
    <tfoot id='ts6Wh'></tfoot>
  • <legend id='ts6Wh'><style id='ts6Wh'><dir id='ts6Wh'><q id='ts6Wh'></q></dir></style></legend>

    1. <small id='ts6Wh'></small><noframes id='ts6Wh'>

      1. <i id='ts6Wh'><tr id='ts6Wh'><dt id='ts6Wh'><q id='ts6Wh'><span id='ts6Wh'><b id='ts6Wh'><form id='ts6Wh'><ins id='ts6Wh'></ins><ul id='ts6Wh'></ul><sub id='ts6Wh'></sub></form><legend id='ts6Wh'></legend><bdo id='ts6Wh'><pre id='ts6Wh'><center id='ts6Wh'></center></pre></bdo></b><th id='ts6Wh'></th></span></q></dt></tr></i><div id='ts6Wh'><tfoot id='ts6Wh'></tfoot><dl id='ts6Wh'><fieldset id='ts6Wh'></fieldset></dl></div>

        Yii 生成没有 Gii 的模型

        Yii generate model without Gii(Yii 生成没有 Gii 的模型)
            <tbody id='L8yp5'></tbody>

          • <bdo id='L8yp5'></bdo><ul id='L8yp5'></ul>
            <legend id='L8yp5'><style id='L8yp5'><dir id='L8yp5'><q id='L8yp5'></q></dir></style></legend>

              <small id='L8yp5'></small><noframes id='L8yp5'>

              <tfoot id='L8yp5'></tfoot>
                <i id='L8yp5'><tr id='L8yp5'><dt id='L8yp5'><q id='L8yp5'><span id='L8yp5'><b id='L8yp5'><form id='L8yp5'><ins id='L8yp5'></ins><ul id='L8yp5'></ul><sub id='L8yp5'></sub></form><legend id='L8yp5'></legend><bdo id='L8yp5'><pre id='L8yp5'><center id='L8yp5'></center></pre></bdo></b><th id='L8yp5'></th></span></q></dt></tr></i><div id='L8yp5'><tfoot id='L8yp5'></tfoot><dl id='L8yp5'><fieldset id='L8yp5'></fieldset></dl></div>

                • 本文介绍了Yii 生成没有 Gii 的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要在不使用 Gii 的情况下生成模型文件.Yii有什么命令吗?

                  I need to generate a model file without the use of Gii. Are there any command Yii?

                  $table = "myTable";
                  Yii::app()->generateModel($table); // ?
                  

                  推荐答案

                  也许官方已经弃用了,你可以用 Yii 命令行工具

                  Perhaps is officially deprecated, you can generate code with Yii Command Line Tools

                  我已经用 Yii 1.1.17 测试过了.

                  I have tested it with Yii 1.1.17.

                  首先你需要在 protected/commands 上创建一个新文件,例如 NewmodelCommand.php 创建一个新的 yii 命令.我们需要避免使用shell交互工具,在控制器、模型等我们的代码中直接调用命令.为了得到它,我们继承了Yii核心类ModelCommand.这个类最初强迫人们在交互式 shell 上输入.

                  First you need to create a new file on protected/commands called for example NewmodelCommand.php to create a new yii command. We need to avoid to use shell interactive tool and call command directly from our code in controllers, models, etc. To get it, we inherit Yii core class ModelCommand. This class originally force person to type on interactive shell.

                  <?php
                  
                  Yii::import('system.cli.commands.shell.ModelCommand');
                  
                  
                  class NewmodelCommand extends ModelCommand
                  {
                  
                  }
                  

                  仅此而已.您可以将 CLI 中的命令测试到您的操作系统中.在 Linux 中,打开终端并转到 /protected/ 目录并键入:

                  That is all. You can test command from CLI into your operating system. In Linux, open your terminal and go to /protected/ directory and type:

                  ./yiic
                  

                  您将看到如下内容:

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

                  稍微玩一下.再次输入:

                  Play a little with it. Type again:

                  ./yiic newmodel
                  

                  您将看到所有命令帮助和文档.

                  And you will see all command help and documentation.

                  要使用此命令生成模型,您至少需要 model_name 作为第一个参数.命令将使用与数据库表名相同的模型名:

                  To generate a model with this command you need at least model_name as first parameter. Command will use same model name as database table name:

                  ./yiic newmodel MyNewModel
                  

                  如果您有不同的模型和数据库名称:

                  If you have different model and database name:

                  ./yiic newmodel MyNewModel tbl_new_model
                  

                  如果您在使用 yiic、定位/连接数据库等方面遇到问题,请确保在 protected/config/console.php 和 查看所有关于 Yii 控制台应用程序的官方文档.

                  If you have troubles using yiic, locating/connecting your db, etc, make sure to setup properly your console environment on protected/config/console.php and check all official docs about Yii console applications.

                  最后在您的代码中,您可以根据需要使用您的命令:

                  Finally in your code you can use your command as you want:

                  $path = '/full/path/to/protected';
                  $new_model_name = 'MyNewModel';
                  shell_exec( $path . "/./yiic newmodel $new_model_name" );
                  

                  这篇关于Yii 生成没有 Gii 的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)

                    <i id='AMkzI'><tr id='AMkzI'><dt id='AMkzI'><q id='AMkzI'><span id='AMkzI'><b id='AMkzI'><form id='AMkzI'><ins id='AMkzI'></ins><ul id='AMkzI'></ul><sub id='AMkzI'></sub></form><legend id='AMkzI'></legend><bdo id='AMkzI'><pre id='AMkzI'><center id='AMkzI'></center></pre></bdo></b><th id='AMkzI'></th></span></q></dt></tr></i><div id='AMkzI'><tfoot id='AMkzI'></tfoot><dl id='AMkzI'><fieldset id='AMkzI'></fieldset></dl></div>
                        <tfoot id='AMkzI'></tfoot>
                      1. <legend id='AMkzI'><style id='AMkzI'><dir id='AMkzI'><q id='AMkzI'></q></dir></style></legend>
                          <bdo id='AMkzI'></bdo><ul id='AMkzI'></ul>

                            <tbody id='AMkzI'></tbody>
                        • <small id='AMkzI'></small><noframes id='AMkzI'>