• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

Pass a variable from one module to another.

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
fun_g
Asked:
fun_g
  • 3
  • 3
  • 3
  • +1
2 Solutions
 
tibidoudouCommented:
Try using the $_SESSION variables.
0
 
tibidoudouCommented:
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
 
heppaCommented:
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
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
fun_gAuthor Commented:
tibidoudou,
That looks like it will totally work. I am checking it out now.
0
 
haijeromeCommented:
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
 
tibidoudouCommented:
yeah, i forgot to mention the top of the page thing...
0
 
heppaCommented:
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
 
fun_gAuthor Commented:
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
 
heppaCommented:
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
 
fun_gAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now