Yii not showing any error - php

Can't make Yii to show error to webbrowser. Configured custom error handler in config:
'errorHandler' => array(
// use 'site/error' action to display errors
'errorAction' => 'site/error',
),
But all errors only got written to application.log and then Apache servers empty page with error 500. How to make Yii print errors to the screen?
index.php:
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

You should a little bit modify your config/main.php. There is an item errorHandler. It should look like this:
'errorHandler' => [
// use 'site/error' action to display errors
'errorAction' => YII_DEBUG ? null : 'site/error',
],
This happened due to increased priority of CErrorHandler::$errorAction. Here is discussion: https://github.com/yiisoft/yii/issues/3760

It might be more of an Apache setting. What you have is correct.
Mine also has this one.
defined('YII_DEBUG_SHOW_PROFILER') or define('YII_DEBUG_SHOW_PROFILER',true);
You can also do this.
error_reporting(E_ALL);
ini_set("display_startup_errors","1");
ini_set("display_errors","1");

read runtime/logs/app.log
you can see any action and error that happens in you yii2 app.

Related

Styling ForbiddenHttpException error in yii2

When I get a ForbiddenHttpException its just ugly black on white text. It's not using the standard pretty Yii2 error from the 'views/site/error.php'
An Error occurred while handling another error: exception
'yii\web\ForbiddenHttpException' with message 'You are not allowed to
perform this action.' in
/vendor/yiisoft/yii2/filters/AccessControl.php:151
Config has:
'errorHandler' => [
'errorAction' => 'site/error',
],
Is it possible to style ALL Yii2 errors to look the same?
First of all check for errorHandler in you main config
'errorHandler' => [
'errorAction' => 'site/error',
],
If it is not there it will show u a plain text.
And for Access Control Custom Error handling you can set a denyCallback in access behaviour
'denyCallback' => function($rule, $action){
// Your Code Goes Here
}

Trying to get property on a non object Yii 1.1.15

I try to change Css file for CGridView widget, in my config/main.php:
'components' => array(
'widgetFactory' => array(
'widgets' => array(
'CGridView' => array(
'cssFile' => Yii::app()->request->baseUrl . '/css/gridview.css',
),
),
),
...
And I get warning:
Trying to get property on a non object /path_to_project/protected/config/main.php on line 79
How I can suppress this warning, and why I getting it, in when I using it in view files it all works.
P.S. Yes I can set display_errors ini set to false and message will dissapearm but I want get clearly with it. Thanks!
The reason for the warning is that the CHttpRequest object Yii::app()->request has not been instantiated yet.
From the API page for CApplication:
CApplication will undergo the following lifecycles when processing a
user request:
load application configuration;
set up error handling;
load static application components;
onBeginRequest: preprocess the user request;
processRequest: process the user request;
onEndRequest: postprocess the user request;
Starting from lifecycle 3, if a PHP error or an uncaught exception occurs, the application will switch to its error handling logic and jump to step 6 afterwards.
Your error is happening at the first step. As such, Yii's error handling has not been setup yet. The only option is to suppress this warning using the # operator:
'cssFile' => #Yii::app()->request->baseUrl . '/css/gridview.css',
HOWEVER
This is a terrible idea, since you are essentially hiding the error instead of fixing it.
If your views are being displayed correctly (no css errors), you can omit the Yii::app()->request->baseUrl and just use:
'cssFile' => '/css/gridview.css'
If you are experiencing errors, you can create a class in your components folder that extends CWidgetFactory and set any variables that depend on other components here e.g
class MyWidgetFactory extends CWidgetFactory {
public function init() {
parent::init();
$this->widgets['CGridView']['cssFile'] = Yii::app()->request->baseUrl.'css/gridview.css';
}
}
You will need to adjust your components to use this file:
'components' => array(
'widgetFactory' => array(
'class' => 'MyWidgetFactory'
...

Logging the requests,response and errors in Yii 1.1.15

How to log all the requests and their corresponding responses in Yii, I tried to log the requests in afterAction, but how to get the responses in afterAction. I also need to log all the errors or exceptions.
You can use afterRender function to get the rendered output. The $output parameter gives you the rendered output. But I think this works only when you have used render function in your controller actions.
Add following to your components configuration in your config file to log errors and warnings
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),

Showing generic error pages to users in Yii 2

I'm using Yii 2 and I'm wondering if Yii has anything built in to handle generic error pages to show to users.
Like for example you may want to show them a general error page because their logout failed for some reason or a range of other reasons. Stuff that you don't want to have to create a view for every situation.
Is there something like this available and if so, how do you use it?
Both the basic and the advance apps come with it by default:
'components' => [
..................
'errorHandler' => [
'errorAction' => 'site/error',
],
..............
class SiteController extends Controller
............
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
You just have to throw an error now and you will see the page.
make sure YII_DEBUG is false.
if YII_DEBUG is true then error stack is displayed.
You can define YII_DEBUG By
1) index.php
//remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
//specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
OR
2).envFramework
YII_DEBUG = true
YII_ENV = dev

How to display standard yii stacktrace?

'errorHandler' => array(
'class' => 'ErrorHandler',
'errorAction' => 'page/find',
),
http://shot.qip.ru/008pAk-4IA4wMhU6/
I have standard error handling with beautiful error page. But for develop environment I need standard stacktrace on it below.
Examlpe: http://shot.qip.ru/008pAk-4IA4wMhU7/
If I comment 'errorAction' I can see just standart stacktrace, in other case I cant display this stacktrace.
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class' => 'CWebLogRoute',
'categories' => 'application, exception.*',
'levels'=>'error, warning, trace, profile, info',
'showInFireBug' => true,
'enabled' => YII_DEBUG,
),
array(
'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',
'ipFilters'=>array('127.0.0.1','192.168.0.100'),
),
array(
'class'=>'CProfileLogRoute',
'report'=>'summary',
// Shows the execution time of each labeled with a code block.
// The value of "report" can also be specified as a "callstack".
),
),
),
Error handler by default uses two types of views for
Production named as error.php;
Development named as named as exception.php;
Based on your routing and error handler code. I see you have defined a custom error action
You will have to place your custom Errors views in either of the following folders, in the format specified in the link below and use the standard error action.
themes/ThemeName/views/system: when a theme is active.
protected/views/system
See this Documentation for detailed explanation
Reference: http://www.yiiframework.com/doc/api/1.1/CErrorHandler
Try this extenstion http://www.yiiframework.com/extension/yii-debug-toolbar/
The Yii Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.
It is a ported to PHP famous Django Debug Toolbar.

Categories