Solved

Pass a variable from one module to another.

Posted on 2010-09-23
10
541 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There is no doubt that cloud is gaining importance. Many of you must have read about this technology and its growing importance. More and more organisations are embracing this technology not forgetting start-ups. The process begins by dipping …
In the wake of AWS' S3 outage, we want to discuss the importance of storage and data diversification in the event of a hack, crash, or system disruption. We spoke with Experts Exchange’s COO Gene Richardson for a deeper understanding.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

627 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