dongzhizhai4070 2012-08-07 22:19 采纳率: 0%
浏览 91
已采纳

路由后uri_to_assoc(n)不起作用

So this currently loads the page for me.

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

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

/controllername/27/shoes

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";

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

    $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

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?

  • 写回答

1条回答 默认 最新

  • douyazi1129 2012-08-07 22:21
    关注

    In this case you'll want ruri_to_assoc:

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

    $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.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀