All time I use:
print'<pre>';
print_r($var);
print'</pre>';
to debug php.
I want to collapse this tree
[params] => JRegistry Object
(
[data:protected] => stdClass Object
(
[show_title] =>
[link_titles] =>
[show_intro] =>
with jquery
I use Kint which is Excellent. To use it, just type :
// shows name of variable, collapsible value and place you called it from
d(varname);
/* pretty stack trace that lets me expand the source, and see
the parameters passed to the function; same is achieved via `d(1);` */
Kint::trace()
Screenshot:
(source: github.io)
Give Krumo a try - http://krumo.sourceforge.net/
Related
Firstly I'd like to apologise in advance if this is a stupid question - Although I have been writing PHP for the last 12 years, I work on bespoke applications and have only been using Magento for the last hour, so I'm clueless on its structure. If possible I'd like to avoid having to dig too much into Magento as the entire reason why I'm using Magento is to save time.
Anyway, the error:
Call to a member function getResourceId() on a non-object in /var/www/[site]/lib/Zend/Acl.php on line 1174
This error occurred after attempting to log in to the administration area immediately after install. The error is in the &_getRules method in lib/Zend/Acl.php.
So, I did a little digging and $resource (the variable it is attempting to call the &_getRules method on) is actually an array - which I found odd as the this is the method definition:
protected function &_getRules(Zend_Acl_Resource_Interface $resource = null, Zend_Acl_Role_Interface $role = null, $create = false){
So, to verify that I wasn't actually losing my mind I wrote the following as the first line of the &_getRules method
if($resource!==null&&!$resource instanceof Zend_Acl_Resource_Interface){
die('<pre>'.print_r($resource,1).' </pre>');
}
Which printed:
Array
(
[G1] => Array
(
[instance] => Mage_Admin_Model_Acl_Role_Group Object
(
[_roleId:protected] => G1
)
[parents] => Array
(
)
[children] => Array
(
[U1] => Mage_Admin_Model_Acl_Role_User Object
(
[_roleId:protected] => U1
)
)
)
[U1] => Array
(
[instance] => bea423c23f6343e2b509fb192a00826f:3EOt7Vo0agtENPH8Wm73EOelgSDoDxYO
[parents] => Array
(
[G1] => Ryan
)
[children] => Array
(
)
)
)
So yeah, i guess my question comes in four parts:
Why doesn't this work out of the box?
Am I just being an idiot?
Why isn't PHP preventing this method from running considering the $resource variable is neither a Zend_Acl_Resource_Interface or null?
How do i fix it?
I should mention that this is a local test site, running on Ubuntu 12.04, Apache 2.4.9 (likely to be nginx in production though), PHP 5.5.12, Magento CE 1.9.0.2.
Thanks in advance,
Ryan
/*************************UPDATE*********************************/
Hi again everyone,
So I've noticed there is a pattern to how this problem/bug/whatever comes around. So, this is my admin url:
http://magento.example.local/admin_system/
If I go to this url, I am able to login and then this issue happens. At this point the url is now
http://magento.example.local/index.php/admin_system/[some_irrelevant_stuff]
So this is where it gets odd. If I then navigate to the original url I am once again redirected to the second url but the beginning of [some_irrelevant_stuff] is /index/denied/ (which I assume is relevant now haha).At this point I am provided the header of the Magento admin panel and I am able to logout.
OK so thats one part of the issue. If I then logout, or if I start my login process at /index.php/admin_system/ then I am able to log in and use the admin area as usual. So, the long and short of it is, I don't know what's going on but I'm hoping this extra info might get me more details.
Thanks for your time,
Ryan
Wow, I am genuinely surprised that nobody had an answer for this. Anyway, the following details are not so much an explanation as to what caused this issue, but a solution to stop it happening.
So, as you'll see from the edit of my question, I noticed that this seemed to have a bizarre connection to the URL and using different URLs to access the admin area (eg. /index.php/admin instead of /admin) caused different errrors. So for this reason, and because having index.php in all my admin area URLs, I took a look into rewriting the admin URLs. This is made available using this plugin: http://www.magentocommerce.com/magento-connect/admin-rewrites.html
If I'm not mistaken, I did not need to make any changes to the RewriteRule(s) that are set by default by magento so following the instructions on the plugin page above should work.
Either way, this appears to resolve the issue so I hope it helps someone having similar issues.
I'm trying to follow this solution to export data to excel but when I click the download link it just says "Server Error. May be down for maintenance....etc"
The only thing I had to change from the tutorial is the name of the Csv helper. The tutorial specifies "Csv.php" but I had to name it "CsvHelper.php". When I print the variable that goes to this view, it displays the array. However, when I remove this and just have the code listed exactly as it appears in that linked post from above I get a server error
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
These are the files that I had to add to my server as directed by the "tutorial"
//Helper
/App/View/Helper/CsvHelper.php
//Vendor
/App/Vendor/excel/PHPExcel.PHP
/App/Vendor/excel/PHPExcel/ //contains the rest of PHPExcel
//view
/App/View/Orders/download.ctp //Tutorial specifies /App/View/Homes/download.ctp so I made sure to change the link accordingly in the view which actually "links" to this
As I mentioned previously when I print the array on download.ctp see this
Array ( [0] => Array ( [Order] => Array ( [id] => 1 [userid] => 2 [order_status] => completed [email] => test#gmail.com [total] => 8.00 ) )
My array's structure matches that of the tutorial which is
$orders[0]['Order'];
Is there something I have to configure with CakePHP for downloading files? I have no idea where to go from here.
Outputting different types of content in cake 2.x is now easy and a "piece of cake" :)
View classes can easily be switched to whatever output you need (json, xml, csv, ..).
In your case I would use https://github.com/josegonzalez/CsvView .
$this->viewClass = 'CsvView.Csv';
and export the data as documented in the plugin readme.
I have been researching this problem for over 12 hours now, with no success.
We have a large custom CMS we have built for a governmental client. The software was developed on PHP 5.3.3. The initial deployment was done on PHP 5.2.2, which caused a few problems, but they finally upgraded their server to PHP 5.3.8. We have little control on exactly which versions gets deployed to their servers.
We have encountered a show-stopper problem. We have an AJAX request which submits a large form via POST with up to 5 levels deep of nested arrays. This has worked fine for several months, but all of a sudden using the new PHP install, we are only getting a partial decode of the data inside the $_POST variable. I have confirmed that PHP is received all the data by inspecting php://input (I also checked that the data was being sent from the browser via Firebug).
This is what we are receiving as the decoded output (via var_dump, I've shortened it for brevity, this should give you a good idea)
Array
(
[db_required_fields] => Array
(
[awr_title] => Array
(
[en] => phil test eng
)
)
[subtitle_intro] => Array
(
[awr_subtitle] => Array
(
[en] =>
)
)
[products] => Array
(
[cp_recall] => Array
(
[1] => Array
(
[product_common_name] => Array
(
[en] =>
)
)
)
)
)
What is missing: each of the [en] should have a peer [fr] array index entry. For example, there should be a [fr] phil test fr entry. Several other index entries at the 2nd array level are missing. The request data itself is not particularly large, roughly 6-7Kb.
What I've done:
- I have had suhosin disabled since it was often mentioned as the cause of similar problems.
- Pored over the phpinfo(); from both a working and the now-working server, trying to identify relevant differences.
- Investigated every module and option within which might affect things (mbstring, for example).
I am now considering writing my own parser for the php://input data, but this seems fraught with (potentially hidden) danger.
Any suggestion or hint ?
I would suggest serializing the post data before sending it. And I would send it as a single string of JSON in one "field." Something like this:
$.ajax({
type: 'POST',
url: 'YOUR URL',
data: {
json: JSON.stringify(form_data) // Where form_data is the JSON object.
},
success: function(response)
{
// Do stuff.
}
});
Then on the server-side, json_decode as follows:
<?php
$_POST = json_decode($_POST['json'], true);
?>
EDIT:
You want json_decode instead of unserialize. Whoops.
You are probably being affected by the new PHP configuration variables max_input_nesting_level or max_input_vars (particularly the latter). Try setting it to a higher value so that PHP doesn't start ignoring some input.
Note, that when you want to change settings like max_input_vars and max_input_nesting_level and you have Suhosin running, you also need to change these params for Suhosin. Example for max_input_vars:
You need to add this to the .htaccess file:
php_value suhosin.post.max_vars 4000
php_value suhosin.request.max_vars 4000
You also need to add the following to your php.ini file in order to allow the change of the suhosin parameters within the .htaccess:
suhosin.perdir = "pr"
"p" allows the change for "post" settings, "r" for request settings.
How am I able to call the built-in WordPress functions (specifically wp_get_user()) in a different file (say, x.php)?
Here's my situation. If I call wp_get_current_user() on the index.php file within my theme directory, it works just perfectly.
However, if I have x.php and called that, I got an error. I googled around, and am now including wp-load.php (at it's correct path). Now it's just giving me an associated array with no values.
The associated array is:
WP_User Object ( [data] => [ID] => 0 [id] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [first_name] => [last_name] => [filter] => )
I tried including index.php in this file, and it still spits out that stuf above, instead of the correct information (which is shown by a print_r on index.php).
Thank you!
try also including the header <?php require('{correct_path}/wp-blog-header.php'); and if that doesn't work also try re-declaring the variables your using to global $var in your wordpress setting php.
See http://codex.wordpress.org/Integrating_WordPress_with_Your_Website
First, use either
<?php define('WP_USE_THEMES', false); require('./wp-blog-header.php'); ?>
or
<?php require('/the/path/to/your/wp-blog-header.php');?>
and then call your WP functions.
this code is originally from Joomla! custom form. All i want is to get the caption on the field and its body variables to put them in an email. I did var_dump($form) and was surprised with what i saw:
stdClass Object ( [FormId] => 10 [FormName] => contacts [FormLayout] =>{global:formtitle}{error}{name:caption}*{name:body}{name:validation}{name:description}{message:caption}*{message:body}{message:validation}{message:description}{email:caption}*{email:body}{email:validation}{email:description}{Send:caption}{Send:body}{Send:validation{Send:description}]
can anyone tell me how should i access those variables? (eg.{name:caption} {name:body})
Thanks in advance.
That is a normal string containing template variables of some sort.
You would have to parse $object->FormLayout using the correct method - it can probably be found inside Joomla's code somewhere.
This is a php object and cannot be accessed like an array $array["FormLayout"]