cs-cart extending core controllers - debugging - php

I'm trying to modify the user's address right after registration.
When you create a new user, The address needs to be modified and a trailing string needs to be added, such as this : ####.
I've created an addon, added the path /controllers/frontend/profiles.post.php,
I've attached to the $mode == 'add' , That's where I'm stuck.
How can I know which variables are available to me, It seems there's no way to debug, var_dump or echo. nothing seems to work.
The file is executing because if I type some broken syntax the server returns 500 internal error,
So my main question :
How can you debug at all any CS-cart addon?

Patrick,
To find out what variables do you have you can use fn_print_r($_REQUEST)
where
fn_print_r - good looking cs-cart wrapper of print_r
Actually the variables from profiles.php are not available in profiles.post.php because these are different variable scopes.
So most probably the only variables you will have is global PHP like $_REQUEST $_SERVER etc..
Take a look at discussion or bestsellers add-on - they have products.post.php controllers which work absolutly the same ways a profiles.post.php and any other post controllers.

Related

PHP Routing - "Clean" include

I have a PHP routing script, like this:
include_once('routing-functions.php');
// pathMatches was imported from routing-functions.php
if(pathMatches('/blog/*')){
include_once('actual-script.php');
}
The problem I have is the following: the functions and global variables from routing-functions.php could potentially conflict with the included file. Additionally, I don't want actual-script.php to have access to any of the variables of the router.
I am looking for a way to completely wipe the PHP context, so that the file is included as if it were directly requested, so doing the following is not an option because it changes the context/scope in which actual-script.php is executed:
if(pathMatches('/blog/*')){
function $sandbox(){
include_once('actual-script.php');
};
$sandbox();
}
Additionally, sending a local request to the file (e.g. with cURL) is also not an option, because it has a negative impact on performance and I want it to run as if it were under the /blog/ URL.
The problem is easy to solve with .htaccess, however, I need a dynamic solution that uses a PHP router.
If anyone has had a similar problem before or knows of a good solution it would be greatly appreciated.

ZF2 - ViewModel children (ViewModel->addChild()) are not rendered

I have following Action in one of my controllers:
public function validateMessageAction() {
$sth = new ViewModel($this->params('params'));
$adServerOutput = $this->forward()->dispatch('Adserver/Controller/Index', array('action' => 'index'));
$sth->addChild($adServerOutput, 'adServerOutput');
return $sth;
}
Next I have a following template:
adServerOutput: <?php echo $this->adServerOutput; ?><br><br>
Validate message link clicked<br>
Of course the Adserver/Controller/Index and corresponding template exists as well, can be called and once called - shows correct output (from its template).
Unfortunatelly what I get after going to validateMessage action is only the "Validate message link clicked" text - nothing that is setup in Adserver/Controller/Index->indexAction().
Any idea why that works this way ?
Additional information to that might be that actually the validateMessageAction() is also triggered from different controller via $this->forward()->dispatch(...) - maybe that might be the case ?
EDIT: I have checked that as well - and even if the forward() call is only done once - still the problem persists...
I will really greatly appreciate any hints - sitting on this for 2 days already and have no clue even what to check further :)
EDIT: ADDITIONAL TESTS and information
I have done some additional tests and found here are some additional info:
adServer/Controller/indexAction has a layout.phtml template that specified layout (for test purposes shows string "AdServer Layout")
validateMessageAction has a layout.phtml tenplate that specified layout as well (for test purposes shows string "validateMessage Layout)
Now when I only try to call
$a = $this->forward()->dispatch(...)
even if $a is not assigned or anyhow used (only this association is performed) - the page immediatelly starts using Adserver layout (but still contents are not shown) - ignoring the layout that was specified for validateMessageAction() (of course when I remove that assotiation - the layout for validateMessageAction() is back immediatelly).
As I understood in the documentation forward should not make any action, but rather only result with string containing rendered module.
There can however be one additional information in here - is that I use EdpModuleLayouts - maybe that might be somehow source of the problem ?
(Posted on behalf of the OP).
Problem was caused by EdpModuleLayouts - removing layout for Adserver (which actually should not have a layout) solved the problem.

ezPublish: Unknown template variable 'view_parameters' in namespace in design/dffestival/templates/page_footer.tpl

We have received below errors on the home page:
eZTemplate # design/dffestival/templates/page_footer.tpl:8[6]:
Unknown template variable 'view_parameters' in namespace ''
In our pagefooter.tpl file have below code:
<div class="attribute-layout">
{attribute_view_gui attribute=$footerNode.data_map.layout view_parameters=$view_parameters}
</div>
We are using eZ Publish Community Project 2012.6 version.
Could anyone explain why I can't retrieve the view_parameters variable and how to do retrieve it?
Thanks
Sunil
Maybe u should start here:
http://www.ezpedia.org/ez/view_parameters
Remember view parameters are by default available only within the
context of the content module and it's views.
All other modules (by default) do not support this feature.
The recommended alternative to view parameters in these situations
would be using get / post parameters instead.
Or here:
https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Templates/Basic-template-tasks/Custom-view-parameters
In some cases $view_parameters won't work, try
$module_result.view_parameters there. So the example above will be:
The color is: {$module_result.view_parameters.color} The amount
is: {$module_result.view_parameters.amount}
Or here (check "$module_result section"):
https://doc.ez.no/eZ-Publish/Technical-manual/3.10/Templates/The-pagelayout/Variables-in-pagelayout
Short answer :
You are trying to retrieve the $view_parameters within the pagelayout (or a template included in it). This is not possible by design and this is completely normal.
Long answer :
View parameters are meant to be used from the views/templates which are used by the content module : for instance, when viewing a content from its alias URL or using its system URL like /content/view/full/2.
They are useful if you want to pass some parameters from the URL to the content view and they are taken into account by the cache system which is a very important thing to keep in mind (this is not the case when using "vanilla" GET parameters).
The main usage is for pagination, for instance : /content/view/full/2/(offest)/2/(limit)10
One of the best practices when developing with eZ Publish (legacy) is to ask yourself : why do you need to retrieve these parameters into your layout ? I guess that you want to control your global layout using them and this is not a good idea.
If you want to control the layout based on something which depends on the content, then I'll suggest to use persistent variables. You will basically use the ezpagedata_set operator in the content/view template and retrieve this value in your pagelayout with ezpagedata() | see https://doc.ez.no/doc_hidden/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Miscellaneous/ezpagedata_set
Last but not least, remember that the module result is computed before the pagelayout (simply because the pagelayout will include this result using $module_result.content).

How can I find out the value of a variable while writing PHP code (for debugging)?

I'm writing in symfony and I'm in one of the actions.class.php files.
Normally I would just echo the variable's value but because this is an actions class module, I can't do that because I can't output to the page.
I was thinking of using FirePHP but it involves installing it server-side and I'd like to be aware of an easier or built-in solution.
Emailing logs works for sure but there are some better, easier and faster ways to do that ;)
In symfony you have access to the Logger which will allow you to log anything. In prod environment by default it is disabled (of course you can switch it on) but in dev it's not only available in the log files but also prints in the Sf Web debug bar.
Inside an action use:
$this->getLogger()->debug('My $variable value is now: '.$variable);
You can also use other levels of logging (->warning(''), ->err(''), ->crit(''), etc.). Of course you need to change the variable to string if it is an array or an object.
In fact you can echo and var_dump things while in the action. They will show in your page (though mess badly with the layout as you're displaying stuff before the actual template).
Remeber that echo works only with strings and numbers. If you try to echo a boolean or array you will see nothing. If you try echo an object it's __toString() method will be used or an error raised.
Email yourself throughout the code. You could either send one at the end of the script or throughout. There are benefits to both. Emailing throughout will easily let you know where something went wrong if you don't get an email and emailing at the end save overhead(doesn't seem like it would be a problem here though).
If you have access to the server's log files, you might want to look into PHP's error_log function. It will print a string into PHP's error log and then you can check the log file.
-edit-: error_log also allows you to email yourself the message. But that's silly.

Passing $_GET[] parameters to a script with Jumi?

I am using Jumi to include a number of PHP scripts on Joomla! articles and it works great. The problem I am having is with passing variables (in the form of $_GET parameters) to a PHP script.
Lets say I have a script "index.php" and I wish to pass the $_GET[] parameter "var" with the value of "10". This would normally be accomplished by pointing to: index.php?var=10. How do "emulate" this functionality with Jumi? I was hoping it would be as simple as:
{jumi [directory/index.php] [var=10]}
The above syntax however is not correct.
Any input would be appreciated.
-- Nicholas
After some trial and error and guidance from the official Joomla! forums I did solve my problem. Rather than passing a true $_GET[] parameter you can pass a $jumi array and reference that.
I wanted to avoid having to rewrite much of my script so what I did was the following.
1) Make the Jumi call like this:
{jumi [directory/index.php] [value]}
2) In index.php:
if(isset($jumi[0]))
{
$_GET['PARAM_YOU_WANT_SET'] = $jumi[0];
}
This is a very simple example of a quick and easy way to emulate passing a $_GET[] parameter to a script using Jumi. This approach saved me a great deal of time because I didn't have to rewrite my controller.
-- Nicholas
This is an old thread I know but there is something that some people might want to know.
If you are wanting to use Jumi with extra parameters in a Module then Nicholas' tip won't work but there is a way to do it.
There is a "Code written" section of the module and a "Source of code" section.
Put the url/path to the file in the "Source of code" section and then define your variables in the "Code written" section...it will pass the variable to the source file before executing so it will do what is desired.

Categories