Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Accessing User State Variables (UserStateFromRequest)

Accessing User State Variables (UserStateFromRequest)

I'm using Joomla 1.5.15 and MetaMod v2.2c

All data is public on my site.  I'm not providing an option for users to login.  I am using User State Variables to pass a state and city code between screens.   Here is the code I'm using:

=============================================================
$mainframe =& JFactory::getApplication();

$state_in = $mainframe->getUserStateFromRequest( "$option.state_variable", 'state', 'state' );
$city_in = $mainframe->getUserStateFromRequest( "$option.city_variable", 'city', 'city' );

=============================================================

Where I'm struggling is figuring out if it's possible to access these variables using MetaMod, and put them in an IF statement, thus returning certain modules by ID.  If it's possible, how do I do that?  Any help that can be provided would be great!

If it's not currently possible, could it be added?

Thanks
Tracy

tracydunn
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Re: Accessing User State Variables (UserStateFromRequest)

Hi Tracy,

what component or module are you currently using with this code? e.g. are you using it in a custom module etc?

The only barrier to using this in MetaMod is that you are relying on some value of $option from wherever you got the code from. Inside MetaMod, $option is set to the option as specified in the URL, e.g. ...&option=com_content... meaning $option = "com_content". I am assuming that is what you are expecting in your code (although it may not be).

So, assuming that the $state_id and $city_id variables are definitely coming up with the right data, you can easily use them in MetaMod rules. Adjust module ids and state/city names as appropriate:

$mainframe =& JFactory::getApplication();
$state_in = $mainframe->getUserStateFromRequest( "$option.state_variable", 'state', 'state' );
$city_in = $mainframe->getUserStateFromRequest( "$option.city_variable", 'city', 'city' );
if ($city_in == 'Los Angeles') return 101; // module #101 for Los Angeles
if ($state_in == 'CA') return 102; // module #102 for the rest of the state of California


Does that help?
Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3319 Posts
User info in posts
Administrator has disabled public posting

Re: Accessing User State Variables (UserStateFromRequest)

Just the help I needed.   Thanks a lot!

tracydunn
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1675
Total Polls:
6
Total Posts:
5917
Posts this week:
6
User Info:
 
Total Users:
11577
Newest User:
owens65784
Members Online:
0
Guests Online:
179

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked