Question

I designed a joomla3 component...

I want to send some parameters to component via URL.

I linked a menu for this component..So I access to this component by this address:

http://examle.com/tag

I have 3 parameters:

years

month

day

example: http://examle.com/tag/2014/12/19

This is my router.php

<?php
defined('_JEXEC') or die ;
function BahaediniBuildRoute(&$query)
{
       $segments = array();
       $app     = JFactory::getApplication();
       $menu        = $app->getMenu();
       $params      = JComponentHelper::getParams('com_bahaedini');
       $advanced    = $params->get('sef_advanced_link', 0);


       if(isset($query['year']))
       {
                $segments[] = $query['year'];
                unset( $query['year'] );
       }
       if(isset($query['month']))
       {
                $segments[] = $query['month'];
                unset( $query['month'] );
       }
       if(isset($query['day']))
       {
                $segments[] = $query['day'];
                unset( $query['day'] );
       }


       return $segments;
}


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

       $segments[0]='items';
       switch($segments[0])
       {

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

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

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



                       break;                                                                
       }
       return $vars;
}?>

So I wana test it. I put some code in a php file in models folder (items.php):

echo "<br>y:".$_date          = urldecode($app->input->getString('year'));
echo "<br>m:".$_date          = urldecode($app->input->getString('month'));
echo "<br>d:".$_date          = urldecode($app->input->getString('day'));

The result are:

y:0
m:12
d:19

You can sea...value of 'y' must be '2014' but it is '0'!

How can I solved this problem? what is my wrong?

Was it helpful?

Solution

Reading your code, BahaediniParseRoute() function, first you assign $segments[0] to 'items', then you try to explode it and read $year from it... it's returning '0' because you're casting $year as int, but it contains 'items'.

Try removing the casts and var_dump($segments) before you assign it 'items' (which makes little sense anyways, why set it and then test it in a conditional loop? you know $segments[0]='items' so what's the point of switch ... case 'items'?

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