Page 1 of 1

Can someone explain JRequest:getWord() ?

Posted: Sun Jan 27, 2008 3:28 am
by ivytony
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!

Re: Can someone explain JRequest:getWord() ?

Posted: Mon Feb 04, 2008 9:18 am
by RobS
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.

Re: Can someone explain JRequest:getWord() ?

Posted: Tue Feb 05, 2008 5:31 pm
by radiant_tech
... 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