简体   繁体   English

在CodeIgniter中将参数从视图传递到控制器

[英]Passing parameters from view to controller in CodeIgniter

I have this basic question 我有这个基本问题

Is this : 这是 :

<a href="userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a> 

Different from this: 与此不同的是:

<a href="/userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a>

Or is there no difference? 或者没有区别?

(I am using CodeIgniter at present) (我目前正在使用CodeIgniter)

Unless I've missed something, the only difference (and there is at least one difference) is in the HTML, not in the PHP per se. 除非我错过了什么,唯一的区别(并且至少有一个区别)是HTML,而不是PHP本身。

The second one has a link that starts with a / , so that means it points to the link at 第二个链接以/开头,这意味着它指向链接

http://yoursite.tld/userconsole/etc

the first one points to /userconsole/etc relative from the place you call it. 第一个指向/userconsole/etc相对于你调用它的地方。 So if you are in the dir /yourpath , it will point you to http://yoursite.tld/yourpath/userconsole/etc 因此,如果您在dir /yourpath ,它会指向http://yoursite.tld/yourpath/userconsole/etc

Lets say ur on www.somesite.com/url/ 让我们在www.somesite.com/url/上说

With

<a href="userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a> 

Ur Going to www.somesite.com/url/userconsole/indivstore/ Ur访问www.somesite.com/url/userconsole/indivstore/

With

<a href="/userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a>

Here is the / important! 这是/重要的! your going back to your root path that means www.somesite.com . 你回到你的根路径,这意味着www.somesite.com The result: www.somesite.com/userconsole/indivstore/ 结果: www.somesite.com/userconsole/indivstore/

So at all its realative vs absolute path. 所以它的所有重建与绝对路径。

The first link has a relative path to the actual page you are visiting, but the second page has the absolute path so: 第一个链接具有指向您正在访问的实际页面的相对路径,但第二个页面具有绝对路径,因此:

If you are at: http://example.com/something/other-thing 如果您在: http://example.com/something/other-thinghttp://example.com/something/other-thing

In first case the next url will be: http://example.com/something/other-thing/userconsole..etc In the second case the next url will be: http://example.com/userconsole..etc 在第一种情况下,下一个网址将是: http://example.com/something/other-thing/userconsole..etchttp://example.com/something/other-thing/userconsole..etc在第二种情况下,下一个网址将是: http://example.com/userconsole..etchttp://example.com/userconsole..etc

<a href="userconsole/indivstore/<?php echo $obj->store_id; ?>/"> is relative URL so if you are on http://host/site/current-page it will point to http://host/site/current-page/userconsole/indivstore/<?php echo $obj->store_id; ?> <a href="userconsole/indivstore/<?php echo $obj->store_id; ?>/">是相对URL,因此如果您在http://host/site/current-page ,它将指向http://host/site/current-page/userconsole/indivstore/<?php echo $obj->store_id; ?> http://host/site/current-page/userconsole/indivstore/<?php echo $obj->store_id; ?> which is wrong http://host/site/current-page/userconsole/indivstore/<?php echo $obj->store_id; ?>哪个错了

<a href="/userconsole/indivstore/<?php echo $obj->store_id; ?>/"> is absolute URL so if you are on http://host/site/current-page it will point to http://host/userconsole/indivstore/<?php echo $obj->store_id; ?> <a href="/userconsole/indivstore/<?php echo $obj->store_id; ?>/">是绝对URL,因此,如果您在http://host/site/current-page ,它将指向http://host/userconsole/indivstore/<?php echo $obj->store_id; ?> http://host/userconsole/indivstore/<?php echo $obj->store_id; ?> which is wrong if your site is under a sub folder. http://host/userconsole/indivstore/<?php echo $obj->store_id; ?>如果您的站点位于子文件夹下,则会出错。

the correct way to generate URL with codeigniter is using site_url() helper please check http://codeigniter.com/user_guide/helpers/url_helper.html 使用codeigniter生成URL的正确方法是使用site_url()帮助程序,请查看http://codeigniter.com/user_guide/helpers/url_helper.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM