How can I view information about a variable or array in symfony 1.4 - debugging

I am trying to learn symfony framework by creating a small project.
Since I started developing the project I have been wondering if there is a convenience function to see the contents or information of a variable or array anywherea in the application by print_r or echo or var_dump (I can use the aforesaid function straight away anywhere in the application but the output is not properly readable in case of large arrays, moreover there are warnings showin like header already sent etc. etc.).
I have also used cakePHP and it has a convenience function named pr() which prints out the contents of variable or array nicely indented (properly readable).
If I had to create such function than how can I make sure that it can be called anywhere in the application?
Any tips (links/blogs/tutorials) related to "how to debug your symfony applications" are greatly appreciated.

To put it simple: you can't output debug "things" in your controller. The controller has nothing to do with the View (output), so when executing it does not know if there's going to be any output.
But, you can output debug "things" in your controller ;-)...
Just print_r() or var_dump(). And immediately die afterwards. That way you can see your debugging.
Call the logger. $this->getLogger()->debug($message);
Add a custom slot which you assign in your controller ($this->getResponse()->setSlot('debug', $debugData)). And include this slot somewhere in your layout file (preferably only in the dev environment.)

Related

How do I access this variable from a different blueprint?

I have found loads of stuff like this on the Internet, but none of it is helping me and I would just love a direct response for this situation.
I have a text UI for my ammo which I simply want to access from the blueprint that handles firing. The text UI has a variable associated with it (At least, I assume this is my text UI):
But for unknown reasons won't let me make it public. That doesn't seem to matter though, because I have experimented with other public variables and I can't access them from my blueprint either!
How can I get access to my variable here so I can do what I wish?
I found your other questions so I assume you're using 4.12, like myself.
So I can use the variable declared in UMG as follows:
Step 1, make a text block, enable it as Is Variable:
Step 2, check it from the Graph part:
Step 3, some other Blueprint, use it:

Best Way To Define Params For A Widget?

I'm creating a widget where there will be 2 types of params:
-The one that can change depending on where we call the widget, those one will be defined in the widget call:
<?php $this->widget('ext.myWidget', array(
'someParams' => 'someValues',
)); ?>
-The one that are the same for all the call to the widget (a path to a library, a place to save an image, ...)
I would like to know what is the best way to define the second type of parameters.
I'm hesitating between making the user define it in the params array in the config file or defining it in an array in the Widget file.
The main advantage of the first option is that the user won't have to modify the Widget file so in case of update his modifications won't be overwritten, but this is not a specific user params so putting it in the parmas array in config file might seem strange.
So what would be the best solution? If there is another one better thant the 2 above please tell me!
Edit:
To clarify my thought:
My widget will generate some images that can be stored in a configurable directory. But since this directory has to be the same each time the widget is called I don't see the point of putting this configuration into the widget call!
This is why I was thinking about putting some params into the config file, in the params array like:
params => array(
'myWidget' => array(
'imageDir' => 'images',
)
)
But I don't know if it is a good practice that an extension has some configuration values in the params array.
Another solution would be to have a config.php file in my extension directory where the user can set his own values so he won't have to modify his main config file for the plugin. But the main drawback of this alternative is that if the user update the extension, he'll loose his configuration.
This is why I'm looking for the best practice concerning the configuration of a widget
Maybe what your looking for is more of an application component than a widget. You've got a lot more power within a component that you have with a widget. It can all still live in your extensions directory, under a folder with all the relevant files, and still be easily called from anywhere but the configuration can then be defined in configuration files for each environment.
When your setting the component in your configs, just point the class array parameter to the extensions folder, instead of the components folder.
Update:
If you do want to use a widget because there's not a lot more complexity, you can provide some defaults within application configurations for widgets I believe, I've never used it myself, see here: http://www.yiiframework.com/doc/guide/1.1/en/topics.theming#customizing-widgets-globally.
But I've found with more complex widgets that a component serves me better in the long run as I can call methods and retrieve options on it much easier and cleaner, but still have everything related to the extension within one folder.

Google Analytics not tracking conversions in Magento 1.7

I'm using Magento's built in Googleanalytics module which is working fine for page views, but not for conversions. The account is set up fine on Google, but it's not adding the addTrans part in the checkout/onepage/success page.
I've done a lot of digging this morning, and found that the observer does observe the "checkout_onepage_controller_success_action" correctly, and does indeed run. It does the following:
$block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('google_analytics');
if ($block) {
$block->setOrderIds($orderIds);
}
I've done some echoing, and it does retrieve the block, and it also sets the order ids correctly. However, in the block itself, if I echo out $this->getOrderIds(); its empty.
My next thought was that perhaps it could be using two GA blocks on the page, and maybe its passing the data to the first one but echoing the HTML of the 2nd one, but I've no clue how to start checking that! The Googleanalytics.xml file only has one block it in, and I don't use that block name anywhere else!
Anyone experienced similar? Or have any idea where I can go from here?
EDIT:
The Ga.php block includes the transaction code if $this->getOrderIds() returns an array, which it is not doing. However, the observer is doing $block->setOrderIds($order_ids); which is passing through an array containing an order id. So the observer is passing the ids to the block, and the block is receiving them (setting up a method of setBlockIds and echoing out the argument, does show the array), but when the block tries to access its own data, it's suddenly not there ($block->getData() returns an array of properties but there is no order_ids property).
I also figured maybe it could be that its echoing the blocks HTML before setting the order id, so I added some variables in to check that and it's not that - its definitely setting the order_ids before trying to get them again, but its still not working!
I'm completely stumped! My only idea now is to modify the Ga.php block to use Magento's registry instead of it's own _data property, which is really not a nice way of doing it!
I think i've been an utter tool. Magento wasn't tracking conversions on the live site because I hadn't put the account code in the configuration part, but I had on my test site.
I had previously put my own analytics code in the template, so I had tracked page views.
When I saw no conversions (despite putting the account code in my test site), I started making orders on the test site and then viewing the source of the order success page. Firefox loads its source as a new request...which automatically goes to the empty basket page. So obviously, it wasn't showing the addTrans or anything, because it had already done that.
A quick check in firebug revealled it was working as it should.
So in the end, after a day of searching, I had to change "No" to "Yes" in the admin, and type in the account code. Great.

Magento - getTreeHtml() - where on earth is this method?

Hopefully somebody can help me with this one as I'm a bit confused.
I'm trying to reverse engineer the product chooser widget so that I can trigger it off a button in the front end. I'm making progress, albeit slow.
One thing that is confusing me though is one of the lines of code in the container.phtml file:
getTreeHtml() ?>
I just cant seem to see where this 'getTreeHtml' method is. I've looked in the template's associated block, the block that that inherits from, and all the way up the object hierarchy. I've also done a text search on the whole of the Magento directory but this method doesnt appear anywhere... Am I missing something here?
Grateful for any help,
Ian
Its a non-declared field accessor (a 'magic' method). Whenever you call a setField(value) or getField() on a Varien_Object without really declaring this methods (they don't exist in the class), Varien_Object checks its $this->data array for a entry with a 'field' key. If such an entry exists it returns/sets the $this->data['field'] value.
The method is used in your Widget. Check out the file:
./Mage/Adminhtml/controllers/Catalog/Product/WidgetController.php:
Somewhere in it you can find this call:
setTreeHtml($categoriesTree->toHtml())
As you can see, the value is set in the controller, and later can be read in the template.

Having one "brain" in a Firefox Addon?

I have an addon that every 5 minuets or so checks an rss feed for a new post, and if there is one, it displays an alert(). Problem is, I'm afraid that if the user opens multiple windows, that when there's a new post a millions of alerts will popup saying the same thing. Is there anyway to have just one "brain" running at a time?
Thanks in advance!
Look up something called "Javascript shared code modules" or JSMs.
Primary docs are here:
https://developer.mozilla.org/En/Using_JavaScript_code_modules
Each .js file in your addon that needs shared memory will open with the following line:
Components.utils.import("resource://xxxxxxxx/modules/[yourFilenameHere].jsm", com.myFirefoxAddon.shared);
The above line opens [yourFilenameHere].jsm and loads its exported (see below) functions and variables into the com.myFirefoxAddon.shared object. Each instance of that object loaded will point to the same instance in memory.
Note that if you want to have any hope of you addon making it past moderation, you will need to write all your code in a com.myFirefoxAddon.* type object as the goons at AMO are preventing approval of addons that do not Respect the Global Namespace
The biggest caveat for JSM is that you need to manually export each function that you want to be available to the rest of your code... since JS doesn't support public/private type stuff this strikes me as a sort of poor-man's "public" support... in any case, you will need to create an EXPORTED_SYMBOLS array somewhere in your JSM file and name out each function or object that you want to export, like this:
var EXPORTED_SYMBOLS = [
/* CONSTANTS */
"SERVER_DEBUG",
"SERVER_RELEASE",
"LIST_COUNTRIES",
"LIST_TERRITORIES_NOEX",
/* GLOBAL VARIABLES */
/* note: primitive type variables need to be stored in the globals object */
"urlTable",
"globals",
/* INTERFACES */
"iStrSet",
/* FUNCTIONS */
"globalStartup",
/* OBJECTS */
"thinger",
"myObject"
]
[edited] Modules are not the right solution to this problem, since the code will still be imported into every window and the whatever listeners/timers you set up will run in every window. You should be careful with using modules for this -- all the timers/callbacks must be set up in the module code (not just using the observer object defined in the module) and you shouldn't use any references to the window in the module.
The right way to do this is I would prefer to write an XPCOM component (in JS). It's somewhat complicated, yes and I don't have a handy link explaining how to do it. One thing: implementing it using XPCOMUtils is easier, older documentation will throw lots of boilerplate code on you.

Resources