我如何传递参数以在kohana框架工作中起作用

时间:2022-12-08 19:48:01

I have following lines of code in bootstap.php for route,

我在bootstap.php中有以下代码行作为路由,

Route::set('ads','ad/<ad>(/<affiliate>)')
->defaults(array(
    'controller' => 'ads',
    'action'     => 'index',
));

Then how I've to pass parameters to that function.Url is localhost/index.php/ads/ is working but when i'm giving localhost/index.php/ads/12 it show 404 error.I know how to access those values in ads.php but how i've to pass the parameters from url.

然后我如何将参数传递给该函数.Url是localhost / index.php / ads /正在工作但是当我给localhost / index.php / ads / 12它显示404错误。我知道如何访问那些ads.php中的值,但我如何从url传递参数。

2 个解决方案

#1


1  

Not sure if it wasn't your typo (ads not ad) but with this route:

不确定这不是你的拼写错误(广告不是广告),而是这条路线:

Route::set('ads','ads/<ad>(/<affiliate>)')
->defaults(array(
    'controller' => 'ads',
    'action'     => 'index',
));

localhost/index.php/ads/12 has to work. In your controller you can access the parameters by:

localhost / index.php / ads / 12必须工作。在控制器中,您可以通过以下方式访问参数:

$this->request->param('ad');

#2


0  

what about

关于什么

Route::set('ads','ad/<ad>(/<affiliate>)', array('affiliate' => '.*'))
->defaults(array(
    'controller' => 'ads',
    'action'     => 'index',
));

#1


1  

Not sure if it wasn't your typo (ads not ad) but with this route:

不确定这不是你的拼写错误(广告不是广告),而是这条路线:

Route::set('ads','ads/<ad>(/<affiliate>)')
->defaults(array(
    'controller' => 'ads',
    'action'     => 'index',
));

localhost/index.php/ads/12 has to work. In your controller you can access the parameters by:

localhost / index.php / ads / 12必须工作。在控制器中,您可以通过以下方式访问参数:

$this->request->param('ad');

#2


0  

what about

关于什么

Route::set('ads','ad/<ad>(/<affiliate>)', array('affiliate' => '.*'))
->defaults(array(
    'controller' => 'ads',
    'action'     => 'index',
));