Can someone explain JRequest:getWord() ?

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
ivytony
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Fri Dec 16, 2005 12:33 am

Can someone explain JRequest:getWord() ?

Post by ivytony » Sun Jan 27, 2008 3:28 am

I'm trying to learn the new rules for Joomla 1.5! components. I don't understand this piece of code:

Code: Select all

<?php>// Require specific controller if requested
if($controller = JRequest::getWord('controller')) {
	$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
	if (file_exists($path)) {
		require_once $path;
	} else {
		$controller = '';
	}
}<?>
What value does this statement confer $controller?
$controller = JRequest::getWord('controller')

if controller is categories, the $path will be component/xxx_component/controllers/categories.php?

I've read the API documentation, but not so useful for understanding getWord()

Thanks!

User avatar
RobS
Joomla! Ace
Joomla! Ace
Posts: 1366
Joined: Mon Dec 05, 2005 10:17 am
Location: New Orleans, LA, USA
Contact:

Re: Can someone explain JRequest:getWord() ?

Post by RobS » Mon Feb 04, 2008 9:18 am

JRequest::getWord() is a proxy method to JRequest::getVar() which is used to get a variable from the request and sanitize it.  The getWord() part means to pass it through what we call the "word" filter.  The word filter allows alphanumeric characters plus underscores and dashes I believe.
Rob Schley - Open Source Matters
Webimagery - http://www.webimagery.net/ - Professional Consulting Services
JXtended - http://www.jxtended.com/ - Free and Commercial Joomla! Extensions

User avatar
radiant_tech
Joomla! Guru
Joomla! Guru
Posts: 531
Joined: Sat Dec 15, 2007 3:02 pm
Location: Washington DC Metro

Re: Can someone explain JRequest:getWord() ?

Post by radiant_tech » Tue Feb 05, 2008 5:31 pm

... and to take that statement a bit further (in case it is still a bit obtuse), it is the method used to obtain GET variables from the URL.  As RobS stated, getWord is a proxy for getVar.  There are many other proxy methods as well such as: getInt() (which returns only digits), getBool() (which returns only true/false values), etc. 

These can all be found in libraries/joomla/environment/request.php


Locked

Return to “Joomla! 1.5 Coding”