Solved

Pass a variable from one module to another.

Posted on 2010-09-23
10
536 Views
Last Modified: 2013-12-12
I have a whole bunch of modules on one page. I would like one module to contain a date selector and make the selected variable available to all of the other modules on that page. How could this be done?

Thank you for your time.
gorg
0
Comment
Question by:fun_g
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 2

Expert Comment

by:tibidoudou
ID: 33743539
Try using the $_SESSION variables.
0
 
LVL 2

Accepted Solution

by:
tibidoudou earned 250 total points
ID: 33743560
to start a session  (u must put this on all you pages) :
session_start() ;

To set variable
$_SESSION['VALNAME'] = $value ;

to get the variable value :

$valname = $_SESSION['VALNAME'] ;

0
 
LVL 4

Expert Comment

by:heppa
ID: 33743772
hey.

1. can you reload the page? then use a request variable 'date', get it through JRequest::getVar('date') and simply register that as "global" variable in any of the modules.

maybe you might have problems with module loading order. would need to test this.

2. instant "application": you would need to use javascript for this. that means that you would have to work on the DOM of other modules.

In general, I don't think, modules should be working this way. Of course they can rely on some other "values" (like virtuemart modules rely on the general shop data), but single modules shouldn't be designed to rely on other module's values. perhaps you rethink this again?

Regards and best of luck...
alex
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:fun_g
ID: 33743779
tibidoudou,
That looks like it will totally work. I am checking it out now.
0
 
LVL 7

Expert Comment

by:haijerome
ID: 33743950
Hi,

    I hope that these instructions are really handy to get exactly what do you need ....
   
    Let me give a brief note what do you need to do ...

    1.  Type the line session_start() (Even before your HTML / everything) in the first line of your PHP codes / modules where you get your Date from the date selector


    2. After that store your Date Variable in a session variable

        $_SESSION['yourvariablename'] = $your_date_variable;

    3. And again Type the line session_start() in the first line of your PHP codes / modules  in other words must be on the top of the pages / modules where you need to have your Date Variable from the date selector...

       And now you can store or print the date variable in the session ..

        Eg :

               echo $_SESSION['yourvariablename'];                     $yourvariablename =  $_SESSION['yourvariablename'];



If it helps then its cool else let me know ...

Regards,Jerome Dennis D
     



       
   
       
0
 
LVL 2

Expert Comment

by:tibidoudou
ID: 33744003
yeah, i forgot to mention the top of the page thing...
0
 
LVL 4

Assisted Solution

by:heppa
heppa earned 100 total points
ID: 33744004
guys, I think you may forget that the session would already be started inside a Joomla module. you would retrieve the session through the JFactory, but I don't think, you need a session variable here, since a once set variable would be available anywhere on the page. But if you insist on using it, please do a:

$session = JFactory#getSession();

0
 

Author Comment

by:fun_g
ID: 33744288
Ok the most basic levels of this are working. The code given by tibidoudou worked right off the bat due to the session handler already implemented in Joomla and pointed out by heppa.

I guess this could be easier still on the method for passing variable because this is technically one module with plugins within. I am customizing community builder to pass the selected date from one tab to the next. Right no the initial date is passed and published but upon changing the date using AJAX  I need to update the selected date in the other tabs. Can this be handled by the session variable passing?

0
 
LVL 4

Expert Comment

by:heppa
ID: 33751299
Good morning!

it depends on how the AJAX call is working. If the AJAX call retrieves it's values through a php you could register the date into the session in that php. I must admit I never used CB, so I don't really know what you are talking about, but the techniques should be the same ...

But this is a completely different scenario from what you described in the beginning ;) In this case you would really need a session variable since the AJAX calls would call different phps that are NOT part of the current page so a variable that would be defined somewhere in the page would not be available in the php that is called via AJAX.

perhaps we would have to look at CB. what exact module are you talking about?
0
 

Author Closing Comment

by:fun_g
ID: 33758891
Experts-
Thank you all for your fast help with this question. I needed to ask it differently but to include the AJAX variable passing, so I wanted to end this question because it was a perfect set of answers and I will be re-asking this to work mostly with AJAX and less with PHP.
Thank you again,
g
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
This Micro Tutorial will explain how to export DynamoDB tables in Amazon Web Services.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question