【问题标题】:Rewriting URL's in codeigniter with url_title()?用 url_title() 重写 codeigniter 中的 URL?
【发布时间】: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);

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

【问题讨论】:

标签: codeigniter url-rewriting uri


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多