Can someone explain JRequest:getWord() ?

For Joomla! 1.5 Coding related discussions, please use:
Forum rules
Please use the mailing list here: rather than this forum.
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Fri Dec 16, 2005 12:33 am

Can someone explain JRequest:getWord() ?

Postby 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()


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

Re: Can someone explain JRequest:getWord() ?

Postby 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 - - Professional Consulting Services
JXtended - - Free and Commercial Joomla! Extensions

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

Re: Can someone explain JRequest:getWord() ?

Postby 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

Return to “Joomla! 1.5 Coding”

Who is online

Users browsing this forum: No registered users and 14 guests