Advertisement
uzielweb

router.php - Componente-Creator.com

Aug 26th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @version    CVS: 1.0.0
  5.  * @package    Com_Ourteammembers
  6.  * @author     Ponto Mega <contato@pontomega.com.br>
  7.  * @copyright  2016 Ponto Mega
  8.  * @license    GNU General Public License versão 2 ou posterior; consulte o arquivo License. txt
  9.  */
  10. // No direct access
  11. defined('_JEXEC') or die;
  12.  
  13. JLoader::registerPrefix('Ourteammembers', JPATH_SITE . '/components/com_ourteammembers/');
  14.  
  15. /**
  16.  * Class OurteammembersRouter
  17.  *
  18.  * @since  3.3
  19.  */
  20. class OurteammembersRouter extends JComponentRouterBase
  21. {
  22.     /**
  23.      * Build method for URLs
  24.      * This method is meant to transform the query parameters into a more human
  25.      * readable form. It is only executed when SEF mode is switched on.
  26.      *
  27.      * @param   array  &$query  An array of URL arguments
  28.      *
  29.      * @return  array  The URL arguments to use to assemble the subsequent URL.
  30.      *
  31.      * @since   3.3
  32.      */
  33.     public function build(&$query)
  34.     {
  35.         $segments = array();
  36.         $view     = null;
  37.  
  38.         if (isset($query['task']))
  39.         {
  40.             $taskParts  = explode('.', $query['task']);
  41.             $segments[] = implode('/', $taskParts);
  42.             $view       = $taskParts[0];
  43.             unset($query['task']);
  44.         }
  45.  
  46.         if (isset($query['view']))
  47.         {
  48.             $segments[] = $query['view'];
  49.             $view = $query['view'];
  50.            
  51.             unset($query['view']);
  52.         }
  53.  
  54.         if (isset($query['id']))
  55.         {
  56.             if ($view !== null)
  57.             {
  58.                 $segments[] = $query['id'];
  59.             }
  60.             else
  61.             {
  62.                 $segments[] = $query['id'];
  63.             }
  64.  
  65.             unset($query['id']);
  66.         }
  67.  
  68.         return $segments;
  69.     }
  70.  
  71.     /**
  72.      * Parse method for URLs
  73.      * This method is meant to transform the human readable URL back into
  74.      * query parameters. It is only executed when SEF mode is switched on.
  75.      *
  76.      * @param   array  &$segments  The segments of the URL to parse.
  77.      *
  78.      * @return  array  The URL attributes to be used by the application.
  79.      *
  80.      * @since   3.3
  81.      */
  82.     public function parse(&$segments)
  83.     {
  84.         $vars = array();
  85.  
  86.         // View is always the first element of the array
  87.         $vars['view'] = array_shift($segments);
  88.         $model        = OurteammembersHelpersOurteammembers::getModel($vars['view']);
  89.  
  90.         while (!empty($segments))
  91.         {
  92.             $segment = array_pop($segments);
  93.  
  94.             // If it's the ID, let's put on the request
  95.             if (is_numeric($segment))
  96.             {
  97.                 $vars['id'] = $segment;
  98.             }
  99.             else
  100.             {
  101.                 $vars['task'] = $vars['view'] . '.' . $segment;
  102.             }
  103.         }
  104.  
  105.         return $vars;
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement