更新时间:2023-02-25 14:34:42
您要获取路径段变量还是GET变量?看来您要兼而有之.
Are you trying to get a path segment variable or a GET variable? It looks like you're going for a bit of both.
在CI中,如果您将URL更新为更像
Natively in CI, you can use $this->input->get
if you update your url to look more like
http://localhost/sitename/some-post-title/?code=24639204963309423
(注意问号).
或者,您可以将URL修改为这样
Alternatively, you can modify your URL to look like this
http://localhost/sitename/some-post-title/code/24639204963309423
然后像这样使用URI段
And then use URI segments like so
$data = $this->uri->uri_to_assoc();
$code = $data['code'];
如果您不想更改URL,则必须像这样手动拆分该字符串
If you do not want to change your URL, you will have to break that string up manually like so
$data = $this->uri->segment(3);
$data = explode($data, '=');
$code = $data[1];
我认为第二个选择是最SEO友好且最漂亮的解决方案.但是这些功能在功能上都应该相同.
I would argue the second option is the most SEO-friendly and pretty solution. But each of these should be functionally identical.