简体   繁体   中英

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.

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:

Sample: localhost/project/index.php?r=site/index
Site is the Controller, index is the Action

However, the project I saw returns URLs like so:
localhost/cdforum/web/index.php/forum/view/id/1

To which my friend said "the htaccess must've been modified" . We assumed the Controller is forum , and the Action is 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?

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:

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

'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/

Then, you can display trace log on your pages:

config/main.php

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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