How to increase CakePHP Debugger maximum depth - ajax

I'm trying to debug my program by logging information from an ajax call. This is something that doesn't render a view, just runs asynchronously. The log will only display arrays to a depth of 3, and the documentation doesn't seem to have any notion that someone might want more information than that.
Please, how do I increase this depth so I can have access to this information without finding weird ways to render my ajax call? Or, if doing this isn't the "Cake" way, is there a better way to output info to a log or console for debugging?

I think this is not the case of CakePHP but an issue with XDebug or PHP configuration itself. You can try to add this line to your php.ini
xdebug.var_display_max_depth = 5
It works if you debug with var_dump(). You should write how do you try to debug, bacause different methods depends on different mechanisms.
If it doesn't work you can try to make the Cake to display original PHP error messages instead of its own error handler messages. In your core.php find code like this:
Configure::write('Error', array(
'handler' => 'displayErrorWithoutCrap',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
And change it into this:
Configure::write('Error', array(
//'handler' => 'ErrorHandler::handleError',
'handler' => 'displayErrorWithoutCrap',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
and add this line at the end of bootstrap.php :
function displayErrorWithoutCrap() {
return false;
}

I ended up submitting a ticket to the Git project for CakePHP and it was confirmed that the debug depth for arrays is hard-coded for log files. The response indicated that it would be considered for a change in the next version.
I ended up finding the number in the Debug class and changed it to a larger number which gave me more depth. Not the best fix, but it works for now until support is added to the next version.

Related

In Laravel, why does "return response()->json([])" take 700 ms longer than "return []"

In Laravel, I can return from a controller like this:
return response()->json(["name" => "Bob"])
Or I can return like this:
return ["name" => "Bob"]
Both of these return the same thing, but the first one takes about 700ms longer. Does anybody know why and how to fix this?
Extra details: Laravel version 8. I'm using Sail (Docker) on my laptop.
More details: I measured the time of the request with Chrome developer tools. I went back and forth a number of times, between the two different ways, with consistent results.
If you want to see the project, here is a stripped down version of it: https://github.com/tkoop/slow_laravel_response
Upon inspecting your project, the package codeat3/blade-google-material-design-icons is the culprit. It depends on blade-ui-kit/blade-icons and according to the readme file, the problem is caching. You can either run php artisan icons:cache (it will still slow down the response by ~100ms) or disable Blade components (no noticeable slow down) if you don't need them:
php artisan vendor:publish --tag=blade-icons
# /config/blade-icons.php
return [
'components' => [
'disabled' => true,
],
];

Passing data to view in laravel

I have the following code
$input = Input::all();
$this->agro->create($input);
$alldata = $this->agro->all();
return View::make('agro.showdata',['myalldata'=>$alldata]);
Here when I return $alldata, all data from database is displayed.I guess here all the data is stored in $alldata variable which we are passing to the showdata view file in the variable myalldata.
Now when in myalldata, if data is not accesses it works as
<h1>DIsplaying data </h1>
But when I try to display data, it gives error Whoops, looks like something went wrong
ie
<h1>Displaying data from database<h1>
{{ $myalldata->title }}
Please help display the data from database.
Another thing, every time something is wrong, it gives error Whoops, looks like something went wrong.How to debug laravel to know where things are going wrong?
It appears that $myalldata is an array of elements. To access each one, you'd need to use a for-loop, like such, in your view:
#foreach($myalldata as $row)
<div>{{{ $row->title }}}</div>
#endforeach
You can determine whether to display the full error trace by modifying your application's app/config/app.php file, and replacing
'debug' => false,
with
'debug' => true,
Keep in mind that, in a production environment (when clients can access the site), you'll want to disable debug mode.
How to debug laravel to know where things are going wrong?
Go to your config/app.php or config/yourEnvironment/app.php and set Application Debug Mode to true.
'debug' => true,

Cant get codeigniter hooks working

I have spent several hours now, trying to figure out why i can't get a simple hook working in codeigniter.
I have enabled hooks in config.
i tripplechecked spelling and case.
I wrote the code below in config/hooks.php:
$hook['pre_controller'] = array(
'class' => '',
'function' => 'set_previous_page',
'filename' => 'previous_page',
'filepath' => 'hooks'
);
And then my previous_page.php file which is located in hooks folder:
function set_previous_page()
{
echo "Hi!"; die;
}
Obviously the purpose is not to echo Hi! and then stop the script execution, but it's just to get it working. And i did try several hook points. But pre_controller i should be able to output hi and kill the script, and then have hi as the only output.
But when i load my pages, it just loads as normal.
I tried on purpose, to mess up the syntax in the hook array, and it did give me an error, and the rest of the page was not loaded. That just tells me that, at least it does recognize that i have turned hooks on.
But from here on i am just lost. Dont know what to do?
Do you have any ideas? I'll try and sleep on it now, and hope that some smart fella in here has the answer! Thankyou in advance!
EDIT: By the way, i am using MX (modular extensions), phil sturgeons template library and Ion auth. Dont really think they should have an impact.
Your code doesn't look like the code in the manual. Did you check it?
http://www.codeigniter.com/user_guide/general/hooks.html
I just tried it locally, and it works fine.
application/config/hooks.php:
$hook['pre_controller'] = array(
'class' => '',
'function' => 'Myfunction',
'filename' => 'Myclass.php',
'filepath' => 'hooks',
'params' => ''
);
application/hooks/Myclass.php:
<?php
function Myfunction(){
echo "wut wut";
die;
}
With this all set, I visit the page and get a wut wut.
You're missing the php extension in the filename, but that'd throw an unexpected end of input exception if everything else was working.
This maybe very late respond, just incase someone encounter this kind of issue same as me using CI 3.x. Just make sure you enable hooks in config/config.php file $config['enable_hooks'] = TRUE; before you put entry in the config/hooks.php

Joomla >1.7 hide log messages from browser

I'm developing an extension for Joomla!; at the moment I'm trying to make it 3.0 compatible - as with 3.0 the logging changed a little (*). Building on the answer from this related question, my current code looks like this:
JLog::addLogger(array(
'text_file' => 'plg_system_myplg.log.php'
));
JLog::add('blah blah log msg');
The problem is that the log also goes to the messages which are shown to the user - this I want to prevent, I want the log msg only to go to the log file. I think it has to do with the "category" that JLog::add takes as a 3rd (optional) parameter, but I have no idea what to pass there?
Can anybody tell me how to hide the messages / or tell me if I'm on the right way with the categories and what value I should use?
Thanks!
(*) It actually changed already with 1.7 as far as I gathered so far, but the old method of calling addEntry on the return of JLog::getInstance(...) seems to have been removed from 2.5 to 3.0.
Edit: Think I found a way now; using:
JLog::addLogger(array(
'text_file' => 'plg_system_myplg.log.php',
JLog::ALL,
'myplg'
));
JLog::add('blah blah log msg', JLog::INFO, 'myplg');
all my log entries go only into my log file (and not to the messages shown to the user). However, I also get a few deprecation warnings - one about my code, but also some unrelated ones:
WARNING deprecated JAccess::getActions is deprecated. Use JAccess::getActionsFromFile or JAcces::getActionsFromData instead.
WARNING deprecated JSubMenuHelper::getEntries() is deprecated. Use JHtmlSidebar::getEntries() instead.
WARNING deprecated JSubMenuHelper::getFilters() is deprecated. Use JHtmlSidebar::getFilters() instead.
WARNING deprecated JSubMenuHelper::getAction() is deprecated. Use JHtmlSidebar::getAction() instead.
Not sure what to make of those - why do they appear in my log file, shouldn't they go to the default error.log file instead of my file ?
This is what I am using, works for Joomla 1.5 - 3.2:
if(version_compare(JVERSION,'1.7.0','ge')) {
jimport('joomla.log.log'); // Include the log library (J1.7+)
$priorities = JLog::ALL ^ JLog::WARNING; // exclude warning (because of deprecated)
// In J3.0 we need to ensure that log messages only go to our file, thus use the categories (already supported in J2.5)
if(version_compare(JVERSION,'2.5.0','ge')) {
$logCategory = 'com_mycomponent';
JLog::addLogger(array('text_file' => $logFileName), $priorities, $logCategory);
JLog::add($msg, JLog::INFO, $logCategory);
}else{
JLog::addLogger(array('text_file' => $logFileName), $priorities);
JLog::add($msg, JLog::INFO);
}
} else {
// Joomla! 1.6 and 1.5
jimport('joomla.error.log'); // Include the log library
$log = &JLog::getInstance($logFileName);
$log->addEntry(array('comment' => $msg, 'level' => 'INFO'));
}
This shows the trick for gettring of the deprecated messages.
And yes, you have to include a category for your messages to ensure they are not showing up as system messages.
Use
new JException('Something happened');
This will only add it to debug log but will not show anything.
It seems, that Joomla 3.0 has no default logger enabled. The same in Joomla 3.0.3. Nothing turns logging on by default - even Debug mode.
Finally I think I have solved my issue with unrelated log entries showing up.
A close look at the API documentation of the addLogger function revealed that the third parameter, $categories, is supposed to be an array of categories for which this log will be used.
This is in contradiction to the version of http://docs.joomla.org/Using_JLog that is current at the time of this writing, where a single category is given instead of an array.
Changing my call to addLogger to use an array, like this:
JLog::addLogger(array(
'text_file' => 'plg_system_myplg.log.php',
JLog::ALL,
array('myplg')
));
And keeping my fingers crossed that this will fix the issue!
Edit: unfortunately even this still doesn't solve my issue - still got unrelated entries :(.
I found the answer.. hope this script make you understand.. I already built as function . this code work on joomla 3. hope work in joomla 2
<?php
function logWrite($level, $values, $file='%s.php',$path='',$showOnTop=0,
$option='',$component=''){
/****
jlog Joomla 3.4
created by:gundambison (2015.04.26).
THX: hbit#stackoverflow
****/
jimport('joomla.log.log');
$level=strtoupper($level);
//You can change this com_name
$component= $component==''? 'com_gundambison': $component;
$date= date("Ymd");
$filename= sprintf($file, $date);
$format= $option=='' ?"{TIME}\t{CLIENTIP}\t{CATEGORY}\t{MESSAGE}": $option;
// create options and text
$txt = is_array($values)? json_encode($values): $values;
$options = array('text_file' => $filename,'text_entry_format'=>$format );
$options['text_file_path']=$path==''?'logs': $path;
JLog::addLogger ($options);
/*
if you want the error to show in your page. just see the different
*/
if($showOnTop==1){
JLog::add("$txt");
}
else{
JLog::add("$level\t$txt",$level,$component);
}
}

How to use translations in Yii console application?

I have created a console Yii application that works as a background worker for a web app - it sends out emails and it needs to send them with translated messages.
For some reason however, the messages are not translated when using Yii::t
If I set the language to something else than english with Yii::app->setLanguage('et_ee'), and check that it is really changed with Yii::app->getLanguage() the texts are always in english.
When I run this same command from web, the texts are correctly translated.
I guess there must be something special I have to do for the translatiosn to work in a console application?
I have this error to. I dont know how is fix it. I am get lang array trow require('path/to/message/ru/message.php') in to var and use it. It is wrong, but it is work for me.
You need to specify the messages component in your console.php configuration
'messages' => array(
'class' => 'CDbMessageSource',
'forceTranslation'=>true,
'sourceMessageTable' => 'source_message',
'translatedMessageTable' => 'translated_message',
),
Just add string (For example - russian languages):
'language' => 'ru'
in config/console.php.

Resources