简体   繁体   English

Yii:如何找出页面中使用了哪些视图,控制器,模型和样式?

[英]Yii: How do I find out which views, controllers, models and styles are being used in a page?

I'm very new to Yii, and I've been asked to take a look at a project, and see if I can add anything. 我是Yii的新手,所以我被要求看一个项目,看看是否可以添加任何东西。

So to start off, I wanted to find out what files are in play for a certain page, ie, what Controller, what View, what Model, etc. A friend, who dabbles in Yii told me it can usually be found via the URL itself, like this: 因此,首先,我想找出某个页面上正在播放的文件,即哪个Controller,哪个View,哪个Model等。一个涉足Yii的朋友告诉我,通常可以通过URL找到该文件。本身,像这样:

Sample: localhost/project/index.php?r=site/index 范例:localhost / project / index.php?r = site / index
Site is the Controller, index is the Action 网站是控制器,索引是操作

However, the project I saw returns URLs like so: 但是,我看到的项目返回如下URL:
localhost/cdforum/web/index.php/forum/view/id/1

To which my friend said "the htaccess must've been modified" . 我的朋友对此表示"the htaccess must've been modified" We assumed the Controller is forum , and the Action is view 我们假设Controller是forum ,而Action是view

We're not exactly sure if that's accurate. 我们不确定这是否正确。 And given a project directory like so: 并给出这样的项目目录:

在此处输入图片说明

I'm not exactly sure what to look for. 我不确定要寻找什么。 So I'd like to ask, for the URL above, is there a way to tell which files are responsible for the output? 因此,我想问一下,对于上面的URL,是否有办法告诉哪个文件负责输出?

You can usually get that from url but not necessarily because routing is defined in your config/main.php file in this part of it: 通常,您可以从url获得该信息,但这不一定,因为路由在此部分的config / main.php文件中定义:

array(
    ......
    'components'=>array(
        ......
        'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                'pattern1'=>'route1',
                'pattern2'=>'route2',
                'pattern3'=>'route3',
             ),
        ),
    ),
);

Check the rules key of this array is the pattern the url is going to have so your pattern will look like 检查此数组的rules键是否为网址的模式,以便您的模式看起来像

'forum/view/...' => 'the/real/url'

then stuff before first backslash is the controller and the second is the action. 然后第一个反斜杠之前的内容是控制器,第二个是动作。 In that action you will be able to find what models are used. 在该操作中,您将能够找到所使用的模型。

Hope it helps 希望能帮助到你

I suggest you to familiarize with this wiki page http://www.yiiframework.com/wiki/249/understanding-the-view-rendering-flow/ 我建议您熟悉此Wiki页面http://www.yiiframework.com/wiki/249/understanding-the-view-rendering-flow/

Then, you can display trace log on your pages: 然后,您可以在页面上显示跟踪日志:

config/main.php config / main.php

'log'=>array(
    (...)

    'routes'=>array(
        (...)

        array(
          'class'=>'CWebLogRoute',
          'levels'=>'trace',
        ),
    ),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM