如何在第二页上使用$ this-uri-segment

时间:2019-07-05 19:52:43

标签: php html codeigniter

我有这些页面的标题带有背景图像。在第一页上,背景显示的图像很好,但是在第二页上显示空白的背景。

我尝试将其更改为segment(2),并在目录上使用不同的名称和不同的图片,但是它无法修复。

这是我使用的行:

style="background-image: url(public/frontend/home/title_bg/<?php echo $this->uri->segment(1)?>.jpg);">

在第一页中,我使用了$this->uri->segment(1),在目录中,我将该文件命名为product.jpg

我可以在第二页上使用具有相同名称和图片的segment(1)吗?以及我该怎么做?

1 个答案:

答案 0 :(得分:0)

确保正确设置uri段。看看这个Codeigniter Samaple。

http://example.com/index.php/news/local/metro/crime_is_up
The segment numbers would be this:

$this->uri->segment(1) = news
$this->uri->segment(2) = local
$this->uri->segment(3) = metro
$this->uri->segment(4) = crime_is_up 

就您而言,我认为您将控制器下的功能命名为产品 然后您得到结果。如果您创建另一个具有相同功能名称的Controller,则可以再次使用segment(1)。建议不要这样做,如果要再次调用图像到另一个函数,只需调用图像名称即可。

url(public/frontend/home/title_bg/<?php echo product.jpg);

让我知道结果。