Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Accessing User State Variables...
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
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
- Index
- » MetaMod
- » MetaMod General Support
- » Accessing User State Variables...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7628
- Newest User:
- horlogekorting34
- Members Online:
- 1
- Guests Online:
- 161
- Online:
- horlogekorting34
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked