3

I'm using yii framework for implementing a new project. I want to see the sql string before it runs on the server. I already enabled this code in my configuration file but I still get no result

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

What should I do exactly to view the sql string when I run a webpage?

2
  • maybe you added that in the wrong place, so please show where exactly within the config you added that line. Commented Nov 12, 2012 at 8:46
  • Use this yiiframework.com/extension/yii-debug-toolbar Commented Nov 12, 2012 at 8:57

4 Answers 4

2

try to put this under components in main.php (config):

'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
        'weblogging'=>array(
            'class'=>'CWebLogRoute',
            'enabled'=>true,
            ),
        ),
    ),

then it will show debugging info along with all the sql ran on that page.

Sign up to request clarification or add additional context in comments.

1 Comment

care to accept the answer? so it will benefit others users as well. thanks.
1

You can make simple logger to log your string to file:

$file = fopen("my.log", "a+");
fwrite($file, $logString."\r\n");
fclose($file);

Comments

1

The configuration array has a key for components, within that you have to add the log component, and within log you are supposed to declare the CWebLogRoute as a route. You will also have to preload the log component.

Minimal example (project-name/protected/config/main.php):

return array(
    // other configurations
    // ...

    // preloading 'log' component
    'preload'=>array('log'), // this is also necessary

    // ...
    'components'=>array(
        // other components
        // ...

        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CWebLogRoute'
                ),
                // ... other routes ...    
            )
        ),

        // ...
    )

);

Read the guide for more tips on logging.

Comments

1

In your config/main.php, after db array add like:

'db'  => array(
 //your db array listing
),
//add following
'log' => array(
    'class'=>'CLogRouter',
    'routes'=>array(
        array(
            'class'=>'CFileLogRoute',
            'levels'=>'error, warning',
        ),
        array(
            'class'=>'CWebLogRoute',
            'levels'=>'trace',
            'categories'=>'system.db.*',
        ),

    ),
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.