dongxing9219 2016-02-15 22:19
浏览 71

如何在php中的路由中添加查询字符串?

I am trying to make the default home page route to certain category by default.

in my routes.php file I have re-routed the publish new action to the home page, as I want the post an ad form to be the home page, but I keep encountering errors when trying to add the query string "?category=wanted-ads"

My goal is I'd like it to default to the form options that are part of the /publish-new.html?category=wanted-ads page.

Apologies for a simple question, I'm new to php and the kohana framework and I'm using the open classifieds script to create a classifieds site.

Thanks in advance.

 URL::title(__('publish new'))

Route::set('post_new', URL::title(__('publish new')).'.html')
->defaults(array(
        'controller' => 'new',    
        'action'     => 'index',
));
  • 写回答

1条回答 默认 最新

  • drl2051 2016-02-15 22:53
    关注

    Did you try get the query string params manually ($_GET)? If yes, what is shown?

    By a fast reading in Kohana docs I found something that could help you. Instead you to pass desired category via query string, you can to pass via params.

    Route::set('post_new', '/post_new/category/:<category>', array('category' => '.*'))
        ->defaults(array(
            'controller' => 'new',
            'action' => 'index',
    ));
    

    To get this param you just do this:

    // From within a controller:
    $this->request->param('category');
    
    // Can be used anywhere:
    Request::current()->param('category');
    

    This works perfectly in many others frameworks, probably works fine in Kohana too.

    Source: https://kohanaframework.org/3.2/guide/kohana/routing#examples

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据