简体   繁体   English

如何将参数正确传递给joomla组件?

[英]how can I pass parameters to joomla component correctly?

I want to send a parameter to a joomla component by Get method 我想通过Get方法将参数发送到joomla组件

This is The URL: 这是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: 这是ParseRoute函数:

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: 通常,URL更改为:

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? 有办法解决这个问题吗?

Use JInput which is the API for managing requests. 使用JInput(用于管理请求的API)。 It's very simple to get anything from the url with JInput. 使用JInput从网址中获取任何内容非常简单。 http://docs.joomla.org/Retrieving_request_data_using_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. 如果您使用的是Joomla,那么重点就是使用API​​,这样您就不必从头开始编写东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM