annuaire recherche
Array Array Helper Benchmarking Benchmarking Class Caching Caching Driver Calendaring Calendaring Class CAPTCHA CAPTCHA Helper Config Config Class Cookie Cookie Helper Database Connecting to your Database Custom Function Calls Database Caching Class Database Configuration Database Forge Class Database Metadata Database Quick Start: Example Code Database Reference Database Utility Class DB Driver Reference Generating Query Results Queries Query Builder Class Query Helper Methods Transactions Date Date Helper Directory Directory Helper Download Download Helper Email Email Class Email Helper Encrypt Encrypt Class Encryption Encryption Library File File Helper File Uploading File Uploading Class Form Form Helper Form Validation Form Validation FTP FTP Class Functions compatibility_functions common_functions HTML HTML Helper HTML Table HTML Table Class Image Manipulation Image Manipulation Class Inflector Inflector Helper Input Input Class Javascript Javascript Class Language Language Class Language Helper Loader Loader Class Migrations Migrations Class Number Number Helper Output Output Class Pagination Pagination Class Path Path Helper Security Security Class Security Helper Session Session Library Shopping Cart Shopping Cart Class Smiley Smiley Helper String String Helper Template Parser Template Parser Class Text Text Helper Trackback Trackback Class Typography Typography Class Typography Helper Unit Testing Unit Testing Class URI URL User Agent XML XML-RPC and XML-RPC Server Zip Encoding Zip Encoding Class XML-RPC and XML-RPC Server Classes XML Helper User Agent Class URL Helper URI Class
personnages

URL帮助文件包含有助于使用URL的功能。

  • 加载此助手

  • 可用职能

加载此助手

使用以下代码加载此助手:

$this->load->helper('url');

可用职能

现有下列职能:

site_url([$uri = ''[, $protocol = NULL]])

参数:

$ uri(string) -  URI字符串$ protocol(string) - 协议,例如'http'或'https'

返回:

网站网址

返回类型:

  • $ uri字符串) -  URI字符串

  • $ protocolstring) - 协议,例如'http'或'https'

Returns:  Site URL
Return type:  string
按照配置文件中的指定返回您的站点URL。index.php文件(或者你在你的配置文件中设置为你的站点**索引\ _page **的文件)将被添加到URL中,你传递给函数的任何URI段以及** url \ _suffix **在你的配置文件中设置。

我们鼓励您在需要生成本地URL时使用此函数,以便在URL更改时页面变得更可移植。

可以选择将段作为字符串或数组传递给函数。下面是一个字符串示例:

echo site_url('news / local / 123');

上面的示例将返回如下内容:http://example.com/index.php/news/local/123

下面是作为数组传递的段的示例:

$ segments = array('news','local','123'); echo site_url($ segments);

此函数是CI_Config::site_url()有关更多信息,请参见配置库文件。

base_url($uri = '', $protocol = NULL)

参数:

$ uri(string) -  URI字符串$ protocol(string) - 协议,例如'http'或'https'

返回:

基本网址

返回类型:

  • $ uri字符串) -  URI字符串

  • $ protocolstring) - 协议,例如'http'或'https'

Returns:  Base URL
Return type:  string
按照配置文件中的规定返回您的网站基础URL。例:

echo base_url();

此函数返回与site_url(),没有指数[医]页URL[医]后缀被追加。

也像site_url(),可以将段作为字符串或数组提供。下面是一个字符串示例:

echo base_url(“blog / post / 123”);

上面的示例将返回如下内容:http://example.com/blog/post/123

这是有用的,因为不像site_url(),您可以向文件(如图像或样式表)提供字符串。例如:

echo base_url(“images / icons / edit.png”);

这会给你这样的东西:http://example.com/映像/图标/ed.png

此函数是CI_Config::base_url()有关更多信息,请参见配置库文件。

current_url()

返回:

当前的网址

返回类型:

uri_string()

返回:

一个URI字符串

返回类型:

index_page()

返回:

'index_page'值

返回类型:

mixed

anchor($uri = '', $title = '', $attributes = '')

参数:

$ uri(字符串) -  URI字符串$ title(字符串) - 锚定标题$ attributes(mixed) -  HTML属性

返回:

HTML超链接(锚标签)

返回类型:

  • $ uri字符串) -  URI字符串

  • $ title字符串) - 锚定标题

  • $ attributesmixed) -  HTML属性

Returns:  HTML hyperlink (anchor tag)
Return type:  string
根据您的本地网站URL创建标准的HTML定位链接。

第一个参数可以包含您希望附加到URL的任何段。就像site_url()函数,段可以是字符串,也可以是数组。

如果您正在构建应用程序内部的链接,请不要包含基本URL(http:// ...)。这将从您的配置文件中指定的信息自动添加。仅包含您希望附加到URL的URI段。

第二部分是你想要链接的文本。如果将其保留为空白,则将使用URL。

第三个参数可以包含要添加到链接中的属性列表。属性可以是简单的字符串或关联数组。

以下是一些例子:

echo anchor('news/local/123', 'My News', 'title="News title"'); // Prints: <a href="http://example.com/index.php/news/local/123" title="News title">My News</a>  echo anchor('news/local/123', 'My News', array('title' => 'The best news!')); // Prints: <a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a>  echo anchor('', 'Click here'); // Prints: <a href="http://example.com">Click Here</a>

anchor_popup($uri = '', $title = '', $attributes = FALSE)

参数:

$ uri(字符串) -  URI字符串$ title(字符串) - 锚定标题$ attributes(mixed) -  HTML属性

返回:

弹出超链接

返回类型:

  • $ uri字符串) -  URI字符串

  • $ title字符串) - 锚定标题

  • $ attributesmixed) -  HTML属性

Returns:  Pop-up hyperlink
Return type:  string
Nearly identical to the [`anchor()`](about:blank#anchor) function except that it opens the URL in a new window. You can specify JavaScript window attributes in the third parameter to control how the window is opened. If the third parameter is not set it will simply open a new window with your own browser settings.

下面是一个具有属性的示例:

$atts = array(         'width'       => 800,         'height'      => 600,         'scrollbars'  => 'yes',         'status'      => 'yes',         'resizable'   => 'yes',         'screenx'     => 0,         'screeny'     => 0,         'window_name' => '_blank' );  echo anchor_popup('news/local/123', 'Click Me!', $atts);

上述属性是函数的默认值,所以你只需要设置与你需要的不同。如果您希望函数使用其所有默认值,只需在第三个参数中传递一个空数组:| | echo anchor_popup('news / local / 123','Click Me!',array());

window_name是不是一个真正的属性,但参数给JavaScript window.open() <http://www.w3schools.com/jsref/met_win_open.asp>方法,它可以接受窗口名称或窗目标。

上面列出的任何其他属性都将被解析为锚标记的HTML属性。

mailto($email, $title = '', $attributes = '')

参数:

$ email(string) - 电子邮件地址$ title(字符串) - 定位标题$ attributes(mixed) -  HTML属性

返回:

“邮件到”超链接

返回类型:

  • $ email字符串) - 电子邮件地址

  • $ title字符串) - 锚定标题

  • $ attributesmixed) -  HTML属性

Returns:  A “mail to” hyperlink
Return type:  string
创建一个标准的HTML电子邮件链接。用法示例:

echo mailto('email protected','点击这里与我联系');

就像anchor()选项卡上,您可以使用第三个参数设置属性:

$ attributes = array('title'=>'Mail me'); echo mailto('email protected','联系我',$ attributes);

safe_mailto($email, $title = '', $attributes = '')

参数:

$ email(string) - 电子邮件地址$ title(字符串) - 定位标题$ attributes(mixed) -  HTML属性

返回:

垃圾邮件安全的“邮件至”超链接

返回类型:

  • $ email字符串) - 电子邮件地址

  • $ title字符串) - 锚定标题

  • $ attributesmixed) -  HTML属性

Returns:  A spam-safe “mail to” hyperlink
Return type:  string
Identical to the [`mailto()`](about:blank#mailto) function except it writes an obfuscated version of the _mailto_ tag using ordinal numbers written with JavaScript to help prevent the e-mail address from being harvested by spam bots.

auto_link($str, $type = 'both', $popup = FALSE)

参数:

$ str(string) - 输入字符串$ type(string) - 链接类型('email','url'或'both')$ popup(bool) - 是否创建弹出链接

返回:

链接的字符串

返回类型:

  • $ strstring) - 输入字符串

  • $ typestring) - 链接类型('email','url'或'both')

  • $ popupbool) - 是否创建弹出链接

Returns:  Linkified string
Return type:  string
自动将包含在字符串中的URL和电子邮件地址转换为链接。例:

$ string = auto_link($ string);

第二个参数决定URL和电子邮件是否被转换,或者仅仅是其中一个.。如果未指定参数,则为默认行为。电子邮件链接被编码为safe_mailto()如上文所示。

仅转换URL:

$ string = auto_link($ string,'url');

只转换电子邮件地址:

$ string = auto_link($ string,'email');

第三个参数确定链接是否显示在新窗口中。该值可以是TRUE或FALSE(布尔值):

$ string = auto_link($ string,'both',TRUE);

url_title($str, $separator = '-', $lowercase = FALSE)

参数:

$ str(string) - 输入字符串$ separator(string) - 字符分隔符$ lowercase(bool) - 是否将输出字符串转换为小写

返回:

URL格式的字符串

返回类型:

  • $ strstring) - 输入字符串

  • $ separatorstring) - 单词分隔符

  • $ lowercasebool) - 是否将输出字符串转换为小写

Returns:  URL-formatted string
Return type:  string
Takes a string as input and creates a human-friendly URL string. This is useful if, for example, you have a blog in which you’d like to use the title of your entries in the URL. Example:

$ title =“CSS有什么问题?”; $ url_title = url_title($ title); //产生:CSS错误

第二个参数确定单词分隔符。默认使用破折号。首选选项是:-(短划线)或_(下划线)

例子:

$ title =“CSS有什么问题?”; $ url_title = url_title($ title,'underscore'); //产生:Whats_wrong_with_CSS

旧用法‘破折号’和‘下划线’作为第二个参数被废弃。

第三个参数确定是否强制使用小写字符。默认情况下他们不是。选项是布尔值TRUE / FALSE。

例子:

$ title =“CSS有什么问题?”; $ url_title = url_title($ title,'underscore',TRUE); //产生:whats_wrong_with_css

prep_url($str = '')

参数:

$ str(string) -  URL字符串

返回:

协议前缀的URL字符串

返回类型:

  • $ strstring) -  URL字符串返回:协议加前缀的URL字符串返回类型:字符串在URL中缺少协议前缀的情况下,此函数将添加http://。将URL字符串传递给像这样的函数:$ url = prep_url('example.com'); redirect($uri = '', $method = 'auto', $code = NULL)参数:$ uri(字符串) -  URI字符串$方法(字符串) - 重定向方法('auto','location'或'refresh')$ code(字符串) -  HTTP响应代码(通常为302或303)返回类型:void

  • $ uri字符串) -  URI字符串

  • $ methodstring) - 重定向方法('auto','location'或'refresh')

  • $ code字符串) -  HTTP响应代码(通常为302或303)

Return type:  void
“标题重定向到”指定的URI。如果指定将构建链接的完整网站URL,但对于本地链接,只需将URI段提供给要指向的控制器即可创建链接。该函数将根据您的配置文件值构建URL。

可选的第二个参数允许您强制使用特定的重定向方法。可用的方法是自动位置刷新,在IIS服务器上位置更快但可靠性更低。缺省值为auto,它将尝试基于服务器环境智能地选择方法。

可选的第三个参数允许您发送特定的HTTP响应代码--例如,这可以用于创建301重定向以用于搜索引擎。默认响应代码为302。第三个参数是可与位置重定向,而不是刷新.例子:

if($ logged_in == FALSE){redirect('/ login / form /'); } // 301重定向重定向('/ article / 13','location',301);

为了使此功能起作用,必须在将任何内容输出到浏览器之前使用它,因为它使用服务器标题。

对于对头的非常细粒度的控制,您应该使用输出库set_header()方法。

对于IIS用户:如果您隐藏Serverhttp标头,汽车方法不会检测到IIS,在这种情况下,建议您显式使用刷新方法。

位置方法时,HTTPStatus代码为303自动当前通过POST访问页面并使用HTTP/1.1时,请选择。

Article précédent: Article suivant: