【发布时间】:2011-01-31 17:28:11
【问题描述】:
我正在用 codeigniter 重写我的网站,并且有一些我想做的事情,但不确定是否可行。
我的网站上有一个由 Flickr API 提供支持的画廊。这是我用来显示风景图片的代码示例:
<?php foreach ($landscapes->photoset->photo as $l->photoset->photo) : ?>
<a href="<?=$l->photoset->photo->farm?>/<?=$l->photoset->photo->server?>/<?=$l->photoset->photo->id?>/<?=$l->photoset->photo->secret?>/<?=$l->photoset->photo->title?>">
<img class="f_thumb" src="<?=$l->photoset->photo->farm?>.static.flickr.com/<?=$l->photoset->photo->server?>/<?=$l->photoset->photo->id ?>_<?=$l->photoset->photo->secret ?>_s.jpg" title="<?=$l->photoset->photo->title?>" alt="<?=$l->photoset->photo->title?>" />
</a>
<?php endforeach; ?>
正如您所看到的,当用户点击图片时,我使用 URI 段传递 Farm、Server、ID、Secret 和 Title 元素,并在控制器中使用
$data['farm'] = $this->uri->segment(3);
$data['server'] = $this->uri->segment(4);
$data['id'] = $this->uri->segment(5);
$data['secret'] = $this->uri->segment(6);
$data['title'] = $this->uri->segment(7);
一切正常,但 URL 有点长。示例:
http://localhost:8888/wip/index.php/gallery/focus/3/2682/4368875046/e8f97f61d9/Old_Mill_House_in_Donegal
有没有办法重写 URL,使其更像:
http://localhost:8888/wip/index.php/gallery/focus/Old_Mill_House_in_Donegal
我正在考虑使用:
$url_title = $this->uri->segment(7);
$url_title = url_title($url_title, 'underscore', TRUE);
但我似乎无法让它工作。有什么想法吗?
【问题讨论】:
-
我不是这方面的专家 - 但根据我有限的理解 - 你不能使用 mod_rewrite 来实现这样的事情 - httpd.apache.org/docs/2.0/misc/rewriteguide.html
标签: codeigniter url-rewriting uri