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.
Related
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.
I am developing a web application that have 3 different acctypes.
Student teacher and admin.
Depending on what acctype is logged in I wan't to load different menus.
I have acctype assigned to a session variable;
#{session.acctype}
So I used to handle it like this;
script(src='js/sidebar#{session.acctype}.js')
But I wanted to get rid of the use of document.write that I used in the js file that was loaded above.
So now I have the menu in a jade file inside.
Here comes the problem, I don't know how to use the session variable to load a jade file!
I tried this without any success;
include sidebar#{session.acctype}.jade
So, is there any way to handle this?
In order to give your templates access to your session variables, you need to add them to res.session.locals. An easy way to accomplish this is by adding
app.use(function(req,res,next){
res.locals.session = req.session;
next();
});
to your application before you call app.use(app.router). This technique is called using middleware.
Im writing a module for PyroCMS,
I need to get the directory of my module that has been installed so I can load an image on the browser.
The image is stored beneath the libraries folder in my module.
I would like to do something like
$logo = $this->get_addon_path(). '/libraries/myfile.png';
Which should return either of these values
www.mysite.com/addons/mysite/modules/mymodule/libraries/myfile.png
www.mysite.com/shared_addons/modules/mymodule/libraries/myfile.png
I managed to find this solution in the code of another program
Id thought id share it.
$this->module_details['path']
For me I just needed to wrap it up like so
base_url() . $this->module_details['path'].'/libraries/gateways/'.$image_name;
Which returns
www.mysite.com/addons/mysite/modules/mymodule/libraries/gateways/myfile.png
I am working on a new module of existing live project. It is a website developed in PHP Zend Framework. New module is on admin side. It runs properly on my localhost/virtualhost.
When I uploaded it online with correct directory path it is found that one file is not found.
It is called like
www.example.com/admin/controllerName/actionName
All the actions works except one action that doesn't display anything and returns exception error mentioning that page or file not found.
What could be the issue? I have checked folders. If one action for the same controller works than why doesn't other. Both have their .phtml files in View section.
Help would be appreciated.
Would I be right if I guessed your local development environment was Windows?
It's probably a filename case sensitivity issue.
Assuming your request looks like
www.example.com/admin/fusionmaps/newpage
I'm not sure how you've setup your modules but if it's reasonably standard, you should have something like this (note the upper and lowercase characters)
application/modules/admin/controllers/FusionmapsController.php
The controller classname should be Admin_FusionmapsController with action public function newpageAction()
The view script should be at
application/modules/admin/views/scripts/fusionmaps/newpage.phtml
I've built two custom modules for Joomla ("reservation" and "contact") which are working just fine, however time to time I have to upgrade them.
Is it possible to make them to share the same "helper.php" so I could keep code in one place? For example the post function is the same for these two modules. I want the "contact" module to use the "reservation" helper.php post function.
Thanks
You can simply include the reservation module helper inside the contact module and use it.
For example lets say that your modules are mod_reservation and mod_contact, in mod_contact.php you include the reservation helper file and use it like this:
require_once JPATH_SITE.DS."modules".DS."mod_reservation".DS."helper.php";
modReservationHelper::post();
Or you make a custom helper module,, which is needed in order for the other 2 to work. I dont know for sure but I thought you can check for other modules when installing a module. In that check you check for the helper module and if not present you give a error. You could also say that a certain module needs atleast version X.XX.XX of the helper module and if the version is too long also give an error in during the install of the module.