I would like to pass some data from a WHMCS admin module to the client summary admin template. In order to get the data from our admin module to the Smarty template, we have been attempting to use an action hook called "AdminAreaPage". This action hook is supposed to take an array of variables (returned in the action hook) and make them accessible as Smarty variables.
The issue I am having is that none of the variables we return in that action hook seem to be accessible to the template (clientssummary.tpl). I have tried listing all available Smarty variables with {debug} as well as several other methods, but none of our custom variables are displayed (the other template variables are successfully listed). The basis for our action hook is taken directly from the WHMCS documentation example:
http://docs.whmcs.com/Hooks:AdminAreaPage
The action hook is running on each page load, as we are able to echo text directly to the page. We are not able to access any data passed to Smarty, however, or we are not passing it correctly. Here is some example code similar to what we are using in our action hook, (nearly unmodified from the WHMCS example code):
function module_hook_test($vars) {
$return = array();
$return = array("field1" => "value1", "field2" => "value2");
return $return;
}
add_hook("AdminAreaPage",1,"module_hook_test");
(with "module" being replaced with our actual module name)
Any assistance with this action hook, or an alternate recommended method of passing the data, would be greatly appreciated. Thank you.
I submitted a ticket to WHMCS support. They have believe the issue may be due to a bug in WHMCS and said that the developers will address the issue in a future release. In the mean time, they suggested querying the data directly from the template using {php}{/php} tags. This will work fine for us as a temporary workaround.
Related
I want to add "Weather: 24C" to the rental-listing component of the super-rentals tutorial app.
Where would be the "best-practices" place to put this ajax request?
Ember.$.getJSON(`http://api.openweathermap.org/data/2.5/weather?q=${location}&APPID=${apiKey}`)
.then(function(json) {
return JSON.parse(json).main.temp;
});
Do I need to add a component, add a model, add a service, add a second adapter, modify the existing adapter? Something else? All of these? Is the problem that the tutorial uses Mirage? I ask this because when I think I'm getting close, I get an error like this:
Mirage: Your Ember app tried to GET
'http://api.openweathermap.org/data/2.5/weather?q=london&APPID=5432',
but there was no route defined to handle this request.
Define a route that matches this path in your
mirage/config.js file. Did you forget to add your namespace?
You need to configure mirage to allow you making calls to outside in case mirage is active; what I mean is using this.passthrough function within mirage/config.js, that is explained in api documentation quite well.
Regarding your question about where to make the remote call is; it depends:
If you need the data from the server to arrive in case a route is about to open; you should prefer putting it within model hook of the corresponding route.
If you intend to develop a component that is to be reused from within different routes or even from within different applications with the same remote call over and over again; you can consider putting the ajax remote call to a component. Even if that is not a very common case usually; it might be the case that a component itself should be wrapped up to fetch the data and display it by itself for reusing in different places; there is nothing that prevents you to do so. However by usually applying data-down action-up principle; generally the remote calls fall into routes or controllers.
Whether using an ember-data model is another thing to consider. If you intend to use ember-data; you should not directly use Ember.$.ajax but rather be using store provided by ember-data and perhaps providing your custom adapter/serializer to convert data to the format ember-data accepts in case the server do not match to the formats that ember-data accepts. In summary; you do not need to use models if you use pure ajax as you do in this question.
I'm trying to use express-flash in a standard web express js app. I don't want to use session, because I want to do the app as stateless as possible, but when I try to use without session, the app show me this error:
req.flash() requires sessions
Can I use express-flash without session? Can I use other alternatives for this kind of messages?
Thanks.
Note: A flash message is a variable stored within a session that is only available once, for the next request. That is if we put a flash variable and renders a page, the flash variable is available but if we render the same (or other) page again the flash variable is not present (it is destroyed).
-- acanimal
Based on this premise, you need to have sessions to use message flashing.
One way I think you can accomplish what you want is to add an item to the request (req) object in your middleware, and then in your controller, check if the key exists. You can then pass a specific message to your template, assuming you're using a template engine or pass it as part of your response.
Hope this helps.
I installed drupal 7 and I need to include a block of PHP code in the user profile page.
I created a new block and I put this code in it:
"include (http://mysite/sites/all/themes/campi_aggiuntivi.php)"
In "campi_aggiuntivi.php" I put the following code:
session_start ();
print_r ($ _SESSION);
But it returns an empty array.
How do I interact with drupal sessions in this external page?
Thank you very much for your answares.
Thank you all for your answers.
I'm trying to install a module and insert it into a block avege as I suggested.
I created the file test.info
name = Test Block
description = description Test Block
package = package Test Block
core = 7.x
dependencies[] = block
; Information added by drupal.org packaging script on 2013-02-01
version = "7.x-1.x-dev"
core = "7.x"
project = "Test Block"
datestamp = "1359680350"
But I can not figure out which function I put in the file test.module, to insert the test module management screen Blocks
Can you help me please?
Thank you again to all
I think you need to include Drupal Bootstrap and a few other necessary procedures. Here's a link to an issue on d.o that might help.
1st thing i want to suggest is don't include like this:
"include (http://mysite/sites/all/themes/campi_aggiuntivi.php)"
Use local path instead: "include (sites/all/themes/campi_aggiuntivi.php)"
But this depends on from where you are calling, if both the files are at same location(calling in user profile tpl file) then this might work: "include (campi_aggiuntivi.php)"
I presume you need session details to figure-out the user id, that information can be retrieved from $profile variable or arg(1)
I have not tested your code but the way you are trying to do is not the conventional way to extend Drupal functionality.
Also i hope print_r ($ _SESSION); is actually print_r ($_SESSION); in your code, i.e. without spaces.
If you want to add a block in user profile page, i recommend doing it the drupal way.
Drupal already has an excellent example for creating a block programmatically. Here is the link.
Have a look at block_example module inside it. It will give you relevant example codes that you can use to create the block.
The example also contains information about how to make the block appear in certain pages by default.
After you create the block place them in the region you would want to, like left sidebar, content etc of the relevant theme that is enabled on user profile pages.
Inside your custom module you would access to $_SESSION variable.
From here on you can include the code in campi_aggiuntivi.php inside your module itself.
Or use the following foolproof method to load the file. This would even work when you call it from a theme.
Say you want to use custom_module_name.campi_aggiuntivi.inc located in your custom module, from a theme then you can use module_load_include
For example,
module_load_include('inc', 'custom_module_name', 'custom_module_name.campi_aggiuntivi');
the above call would load custom_module_name.campi_aggiuntivi.inc from custom_module_name module folder. This way you don't have to hard code the path required to access the file.
Based on your update.. it sounds like you are now trying to create a block programmatically. There are example modules that you can download on Drupal.org. There is a block module in that download.
I thought this would be simple but I guess there's a catch somewhere...
I'm developing a custom part of code for a Joomla installation and I need to unset some session variables before executing my code. So, naturally, I have
$session->clear('var1');
$session->clear('var2');
$session->clear('var3');
$session->clear('var4');
but the page appears totally blank and nothing happens. Any suggestions?
Assuming that you got the $session variable like this:
$session = JFactory::getSession();
If you are getting a blank page, you probably some error in your code. Do you have access to some kind of error log? If not, you can try to force displaying errors from your code if it's not a production environment (although it's not the best way to do it) or enable debug mode from the joomla administrator.
You can also try to run the php file in your browser, and if everything is ok and there are no parse errors in the file, you should see a message like 'Restricted access' or similar.
Besides, if the script is not crashing, you can check what value is returning each call to $session->clear( 'xxx' ) (It should return the value you just cleared.
The last thing that comes to my mind is that the vars you have stored in session are in a different "context". When you get/set data to session, you can pass a "namespace" as an additional parameter, so these vars are stored in that "namespace" (in fact, it's stored inside another index inside the session. So if possible, you should check if these variables are stored in session using a different "namespace":
$session->set( 'var1', $value, 'another_namespace' );
If so, you should clear it like this:
$session->clear( 'var1', 'another_namespace' );
P.S.: I said "namespace" because it's the parameter name that Joomla uses in these session methods, but don't get confused with PHP namespaces.
I hope it helped!
I took over an implementation of Magento Enterprise.
There is a URL that looks something like this:
mydomain.com/our-solutions
It's got a dynamic part to it; under the CMS tab in the Admin I don't see anything that matches that URL.
In the extended local files, I don't see anything in the config for it but it seems to know to load up a particular template.
I need to be able to modify the controller for this particular page. Any advice would be great.
Thanks.
The quick and dirty way would be to temporarily add some debugging code to the following file
# File app/code/core/Mage/Core/Controller/Front/Action.php
public function preDispatch()
{
//log out the class name
Mage::Log( get_class($this) );
//or just dump it if you don't know how logging works
var_dump(get_class($this));
$this->getLayout()->setArea($this->_currentArea);
parent::preDispatch();
return $this;
}
This will let you discover which class file is the controller for the request, and you can code trace from there.
Also (shameless plug time) I build and sell a commercial product that will (among other things) allow you to (among other things) instantly zero in on which controller, block, model, or collection was used for a particular request. There's a demo page you can checkout, and while it's clearly self-serving of me to mention it, I also truly believe it's the best way for a developer to work with Magento.