Solved

Pass a variable from one module to another.

Posted on 2010-09-23
10
534 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Why do Marketing keep bothering you?

Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

Join & Write a Comment

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
The viewer will learn how to count occurrences of each item in an array.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now