I have this URL (part of the url): index.php?option=com_umpai&status=success
When status = success is pass to component, i want it to run success task. So i created a router php file to get status and put in task. Not sure if this is a correct method to do it? How can i put in the task by getting status in my url?
I am wondering does router.php apply to url type in the address bar?
This is my router codes:
<?php
defined('_JEXEC') or die('Restricted access');
function UmpaiBuildRoute(&$query)
{
$segments = array();
if(isset($query['status']))
{
switch($query['status']) {
case 'success':
$segments[] = 'success';
case 'fail':
$segments[] = 'fail';
case 'cancel':
$segments[] = 'cancel';
}
$segments[] = $query['task'];
unset($query['task']);
unset($query['status']);
}
return $router->build($segments);
}
function UmpaiParseRoute($segments)
{
$vars = array();
$count = count($segments);
if(!empty($count)) {
if($segments[0] == 'success'){
$vars['task'] = 'success';
}
}
return $router->parse($vars);
}
This is the simple code version to test if my router is working, but it is not working too:
function UmpaiBuildRoute(&$query)
{
$segments = array();
$segments[] = 'success';
return $segments;
}
function UmpaiParseRoute($segments)
{
$vars = array();
$count = count($segments);
if(!empty($count)) {
if($segments[0] == 'success'){
$vars['task'] = 'success';
}
}
return $vars;
var_dump($vars);
}
I tried this as well:
function UmpaiBuildRoute(&$query)
{
$segments[] = $_GET['status'];
}
function UmpaiParseRoute($segments)
{
$vars = array();
$count = count($segments);
if(!empty($count)) {
if($segments[0] == 'success'){
$vars['task'] = 'success';
}
}
return $vars;
}
Verhaeren (in the comments for the question) is right, try this:
if(!empty($_GET['status'])) {
// if status is set:
switch($_GET['status']) {
case 'success':
$segments[] = 'success';
case 'fail':
$segments[] = 'fail';
case 'cancel':
$segments[] = 'cancel';
}
} else {
// if status is not set...
};
Note: instead of this switch, you could also use $segments[] = $_GET['status'];
$_GET
is an array but $_GET['status']
is a string. $_GET
is an array with all URL variables (if any).
function UmpaiParseRoute()
{
$vars = array();
if(isset($_GET['status'])) {
$vars['task'] = 'success';
}
return $vars;
}
Also notice you don't need to pass $_GET
as a parameter because is a SUPERGLOBAL variable.