Question

I want to send a parameter to a joomla component by Get method

This is The URL:

index.php?option=com_bahaedini&search=keyword&view=items&year=yyyy&month=mm&&day=dd

ex:

index.php?option=com_bahaedini&search=ebooks&view=items&year=2000&month=1&&day=20

This is ParseRoute function:

function BahaediniParseRoute($segments)
{
       $vars = array();


       switch($segments[0])
       {

               case 'items':
                       $vars['view'] = 'items';

                       if(isset($segments[2]))
                       {
                       $year = explode( ':', $segments[2] );
                       $vars['year'] =  (int)$year[0];
                       }

                       if(isset($segments[3]))
                       {
                       $month = explode( ':', $segments[3] );
                       $vars['month'] = (int)$month[0]; 
                       }

                       if(isset($segments[4]))
                       {
                       $day = explode( ':', $segments[4] );
                       $vars['day'] = (int)$day[0]; 
                       }

                       if(isset($segments[1]))
                       {
                       $search = explode( ':', $segments[1] );
                       $vars['search'] = (int)$search[0]; 
                       }

                       break; 


       }
       return $vars;

Normally The URL changes to:

http://127.0.0.1/component/bahaedini/items/ebooks/1395/1/8

I print them with this method:

echo "<br>s:".$_ss          = urldecode($app->input->getString('search'));
echo "<br>y:".$_yy          = urldecode($app->input->getString('year'));
echo "<br>m:".$_mm          = urldecode($app->input->getString('month'));
echo "<br>d:".$_dd          = urldecode($app->input->getString('day'));

result:

ss=ebook/yy=2000/mm=1/dd=8

every thing is normal UNTIL: If I remove keyword this is the result:

ss=2000/yy=1/mm=8/dd=

Is there a way to solve this problem?

Was it helpful?

Solution

Use JInput which is the API for managing requests. It's very simple to get anything from the url with JInput. http://docs.joomla.org/Retrieving_request_data_using_JInput.

$jinput = JFactory::getApplication()->input;
$year = $jinput->getInteger('year'); // not sure why you have year as a string
$keyword = $jinput->getString('keyword');

If you are using Joomla the whole point is to use the API so that you don't have to write things from scratch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top