用url_title()重写codeigniter中的URL?

时间:2010-03-25 13:17:52

标签: codeigniter url-rewriting uri

我正在使用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);

一切正常并且很好,但网址有点长。例如:

http://localhost:8888/wip/index.php/gallery/focus/3/2682/4368875046/e8f97f61d9/Old_Mill_House_in_Donegal

有没有办法重写网址,因此更像是:

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

但我似乎无法让它发挥作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

内部链接是否链接?或者他们链接到flickr?如果它在内部,我想你可以通过POST传递所有必要的信息。如果是flickr,我认为没有办法可以控制他们希望如何获得特定项目的请求。

所有额外信息(秘密,服务器等)的最终目的是什么?