I followed this tutorial but still I go to the webpage refresh, then go to the file and still I can't find the log message I sent
I wrote the following line in a controller:
Yii::log("Index Checkout",CLogger::LEVEL_ERROR);
And My configurations:
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'logFile'=>'trace.log',
'class' => 'CFileLogRoute',
'levels' => 'error,info, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
Right way to write to log is:
Yii::log($message, $level, $category);
But point is that $category should not be empty.
Example above works becouse message is written in category then category is not empty, but it writes empty message. It writes category so it looks like message.. but it isn't.
I was in a similar trouble with YII logger. Strange but I was kind of messing with parameter order.
This works for me:
<?php
Yii::log('', CLogger::LEVEL_ERROR, 'Message Here...');
Related
Hey I'm sure I miss something obvious, but can't figure out what it is :
I can't get a simple hook working with my quasi blank installation of CI 3 ...
I've put the simplest of the code possible with a Hook called MyTest and it works fine :
application/config/hooks.php
$hook['post_controller_constructor'][] = array(
'class' => 'MyTest',
'function' => 'TestMe',
'filename' => 'MyTest.php',
'filepath' => 'hooks',
'params' => ''
);
application/hooks/MyTest.php
class MyTest{
function TestMe()
{
die("die by the hook TEST");
}
}
->this outputs "die by the hook TEST", which is what is expected.
But almost the same with a Hook called URI_Actions doesn't work at all :
application/config/hooks.php
$hook['post_controller_constructor'][] = array(
'class' => 'URI_Actions',
'function' => 'index',
'filename' => 'URI_Actions.php',
'filepath' => 'hooks',
'params' => ''
);
application/hooks/URI_Actions.php
class URI_Actions{
function index()
{
die("die by the hook URI Actions");
}
}
-> this doesn't output anything ... I'm sure I'm missing something enormous, any idea ?
Epilogue
Of course the problem was elsewhere : binary FTP transfert was the issue, once the files uploaded normally the same codes worked perfectly. Thanks to trajchevska which made me realize the code was not the problem !
Does it not display anything or it displays "die by the hook TEST" only? The thing is that you have them both defined one after the other and they're both doing dump and die. So when the Test hook displays the result, the program dies and doesn't get to the URI_Actions hook.
Try using a simple var_dump instead of die, you should get the expected result. I tested both locally and they work fine.
Working in Yii, i get the error of
SystemManagementController and its behaviors do not have a method or
closure named "createReturnableUrl"
I can not find anything to solve it. it happened right after I added this:
array(
'class' => 'CButtonColumn',
//'viewButtonUrl' => '$this->grid->controller->createReturnableUrl("view",array("id"=>$data->id))',
'updateButtonUrl' => '$this->grid->controller->createReturnableUrl("update",array("id"=>$data->id))',
'deleteButtonUrl' => '$this->grid->controller->createReturnableUrl("delete",array("id"=>$data->id))',
//'deleteConfirmation' => Yii::t('app', 'Are you sure to delete this item?'),
),
to :
<?php
//The following lines needs to be moved to the controller to sepparate the view from the controllers.
$model = new CActiveDataProvider('User');
//The following line should be set by the controller. Containing the names of the colums in a chosen language.
/**/
$colums = array(
'login',
'name_first',
'name_last',
//'password',
'email',
'is_active',
//'sortorder',
array(
'class' => 'CButtonColumn',
//'viewButtonUrl' => '$this->grid->controller->createReturnableUrl("view",array("id"=>$data->id))',
'updateButtonUrl' => '$this->grid->controller->createReturnableUrl("update",array("id"=>$data->id))',
'deleteButtonUrl' => '$this->grid->controller->createReturnableUrl("delete",array("id"=>$data->id))',
//'deleteConfirmation' => Yii::t('app', 'Are you sure to delete this item?'),
),
);
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model,
'columns' => $colums,
'filter' => $model->model)
);
?>
when I remove that piece of code, there is not problem, everything works, but when I add that line it gives me the error.
I use that line in a different class as well and there I dont get the problem, how can I get rid of this?
It looks like the controller does not know about createReturnableUrl. From what I googled that is a behavior of yii that you can attach, are you sure you attached the behavior properly for the SystemManagementController? See if all the other controller that work with the same code have that behavior attached, maybe this one does not.
I know how to make response routes in the actual /config/routes.php file, but I can't find where to change the default 'fetal dispatcher' error. I'd like to be able to have it route to a nice 404 page I've made when there's a missing page/action controller. Is that possible?
Yes, you can take advantage of lithium\core\ErrorHandler for this. See the code in the default config/bootstrap/errors.php:
ErrorHandler::apply('lithium\action\Dispatcher::run', array(), function($info, $params) {
$response = new Response(array(
'request' => $params['request'],
'status' => $info['exception']->getCode()
));
Media::render($response, compact('info', 'params'), array(
'library' => true,
'controller' => '_errors',
'template' => 'development',
'layout' => 'error',
'request' => $params['request']
));
return $response;
});
This is saying, if any exception occurs during Dispatcher::run(), display the development.html.php template from the views/_errors folder with the layouts/error.html.php layout.
So you can change that -- maybe you check the Environment to see if this is a dev or production environment and display a different template for production.
Maybe if $info['exception']->getCode() === 404, you can switch to a template specifically for 404 errors.
I made typical form with ZF2 form and wanted to add validation using ZF2 InputFilter. It was success but the colour of error message is black which is looks strange. I tried to change the colour by using method I've searched like this:
array(
'name' =>'NotEmpty',
'options' => array(
'messages' => array(
NotEmpty::IS_EMPTY => '<div style="color:red;">Please enter User Name!</div>'
),
),
),
But, instead of message's colour changed to red, it showed the tag with style, in other word, just plain HTML. What is the proper way to achieve my need?
Easiest way would be to modify the view helper ;)
Inside your module.config.php
'view_helpers' => [
'factories' => [
'formelementerrors' => function($vhm) {
$fee = new \Zend\Form\View\Helper\FormElementErrors();
$fee->setAttributes([
'class' => 'your error classes'
]);
return $fee;
}
]
]
The alternate approach when rendering errors using $this->formElementErrors() would be to add the error classes inside the ViewHelper directly
$this->formElementErrors($element, ['class' => 'my error classes']);
I am trying to handle errors on my website. I logs each error in my log files, but I would like to know how to customize the message that is recorded in the log file.
For now, I get this message:
2013/09/30 10:08:59 [error] [exception.CException] exception
'CException' with message 'Error test' in
myDomain.com\protected\controllers\SiteController.php:234
Can you help me?
For manual customization log messages you need to create your own LogRoute class. In your situation you need inherit class from CFileLogRoute and override method formatLogMessage (such in example):
class MyFileLogRoute extends CFileLogRoute{
protected function formatLogMessage($message,$level,$category,$time)
{
//enter code here your custom message format
return #date('Y/m/d H:i:s',$time)." [$level] [$category] $message\n";
}
}
Than configure your configuration file:
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'MyFileLogRoute',
'levels' => 'error, warning, info',
'categories' => 'application.*',
'logPath' => dirname(__FILE__).'/../../../../../logs/',
),
...
And yes, #ragingprodigy is right: you can set define('YII_DEBUG', 0) or define('YII_TRACE_LEVEL', 0) in index.php to remove stack trace from log messages