uri_to_assoc(n)路由后不能工作

时间:2021-12-31 07:42:33

So this currently loads the page for me.

这是目前为我加载的页面。

/controllername/view/id/27/title/shoes

/ controllername /视图/ id / 27 /标题/鞋

However, I want the user to be able to type in:

但是,我希望用户能够输入:

/controllername/27/shoes

/ controllername / 27 /鞋

to view the file. So in the routing file, I made a rule like this,

查看该文件。在路由文件中,我做了一个这样的规则,

$route['controllername/(:num)/(:any)'] = "controllername/view/id/$1/title/$2";

$路线[' controllername /(num)/(任何)')=“controllername /视图/ id / $ 1 /标题/ $ 2”;

The original address works with uri_to_assoc(n) because I have it as

原始地址使用uri_to_assoc(n),因为我有它。

    $array = $this->uri->uri_to_assoc(3);
    $id = $array['id'];
    $title = $array['title'];

But once I route it and use the new address to access the file, I get the errors: Message: Undefined index: id Message: Undefined index: title

但是,一旦我路由它并使用新地址访问文件,就会得到错误:Message: Undefined index: id Message: Undefined index: Undefined index: Undefined index: title: title

I do not get these errors with my original url way of accessing it. I guess the value of uri_to_assoc(3) changes once the url is changed but I thought the routing function would take care of that. Can anyone help me get rid of these variable errors?

我没有得到这些错误与我的原始url方式访问它。我猜uri_to_assoc(3)的值会随着url的改变而改变,但我认为路由函数会处理这个问题。谁能帮我去掉这些变量错误吗?

1 个解决方案

#1


1  

In this case you'll want ruri_to_assoc:

在这种情况下,您需要ruri_to_assoc:

http://codeigniter.com/user_guide/libraries/uri.html

http://codeigniter.com/user_guide/libraries/uri.html

$this->uri->ruri_to_assoc(n)

$ this - > uri - > ruri_to_assoc(n)

This function is identical to [uri_to_assoc], except that it creates an associative array using the re-routed URI in the event you are using CodeIgniter's URI Routing feature.

这个函数与[uri_to_assoc]相同,只是在使用CodeIgniter的URI路由特性时,它使用重新路由的URI创建一个关联数组。

You should still validate your array indices anyways, in case the URL itself is invalid.

您仍然应该以任何方式验证数组索引,以防URL本身无效。

#1


1  

In this case you'll want ruri_to_assoc:

在这种情况下,您需要ruri_to_assoc:

http://codeigniter.com/user_guide/libraries/uri.html

http://codeigniter.com/user_guide/libraries/uri.html

$this->uri->ruri_to_assoc(n)

$ this - > uri - > ruri_to_assoc(n)

This function is identical to [uri_to_assoc], except that it creates an associative array using the re-routed URI in the event you are using CodeIgniter's URI Routing feature.

这个函数与[uri_to_assoc]相同,只是在使用CodeIgniter的URI路由特性时,它使用重新路由的URI创建一个关联数组。

You should still validate your array indices anyways, in case the URL itself is invalid.

您仍然应该以任何方式验证数组索引,以防URL本身无效。