menu

Codeigniter URL Helper


Codeigniter URL Helper – Codeigniter URL Helper contains functions That is used for parsing the URL And break Down Into Several Segment and pass to the Controller Or store as a Variable.$this->load->helper(‘url’); is used to load the helper. Here in this tutorial, we are going to explain how to use URL helper in CodeIgniter.


Codeigniter URL Helper Example

Let us first see how to load URL helper in codeigniter and then use its function-

Load URL Helper

How To Load URL Helper in Codeingniter Example:

Functions:-

There are many functions are available in URL helper. Now we will explain one by one with example.

    • 1. Site URL, Base URL, The current URL
    • 2. An URI string
    • 3. index_page value
    • 4. hyperlink (anchor tag)
    • 5. Pop-up hyperlink
    • 6. A “mail to” hyperlink and safe “mail to” hyperlink
    • 7. Linkified string
    • 8. URL-formatted string
    • 9. Protocol-prefixed URL string
    • 10. redirect

    1. Site URL, Base URL, The current URL

    This Function is used to work with url like Site, Base and Current url:-

    Syntax of Site URL, Base URL, The current URL function is:-

      Parameters:

    • $uri (string) : URI string
    • Return type : string

    EXAMPLE

    Here is simple example of Site URL, Base URL, The current URL.

    Site URL, Base URL, The current URL in Codeigniter Example:-

    The output will be like this –

    2. An URI string

    This Function is used to redirect directory path . Syntax of An URI string function is:-

    Syntax of An URI string function is:-

      Parameters:

    • $uri (string) : URI string
    • Returns : uri string
    • Return type : string

    EXAMPLE

    Here is simple example of An URI string.

    An URI string in Codeigniter Example:-

    This Helper return only uri string

    The output will be like this –

    3. index_page value

    Syntax of index_page value function is:-

    Syntax of index_page value function is:-

      Parameters:

    • Returns : index_page value
    • Return type : mixed

    EXAMPLE

    Here is simple example of index_page value.

    index_page value in Codeigniter Example:-

    The output will be like this –

    4. hyperlink (anchor tag)

    This Function is used to create standard html anchor link based on your local url. It accept three parameters-Uri strings, title and attributes:-

    Syntax of hyperlink (anchor tag) function is:-

      Parameters:

    • $uri (string) : URI string
    • $title (string) : Anchor title
    • $attributes (mixed) : HTML attributes
    • Returns : HTML hyperlink (anchor tag)
    • Return type : string

    EXAMPLE

    Here is simple example of hyperlink (anchor tag).

    hyperlink (anchor tag) in Codeigniter Example:-

    The output will be like this –

    5. Pop-up hyperlink

    Pop-up Hyperlink function is used to create html anchor link on new window. Syntax of Pop-up hyperlink function is:-

    Syntax of Pop-up hyperlink function is:-

      Parameters:

    • $uri (string) : URI string
    • $title (string) : Anchor title
    • $attributes (mixed) : HTML attributes
    • Returns : Pop-up hyperlink
    • Return type : string

    EXAMPLE

    Here is simple example of Pop-up hyperlink.

    Pop-up hyperlink in Codeigniter Example:-

    The output will be like this –

    6. A “mail to” hyperlink and safe “mail to” hyperlink

    This function is used to Create link on mail by these functions. It Has three parameters- email string, Title and attributes. Syntax of A “mail to” hyperlink and safe “mail to” hyperlink function is:-

    Syntax of A “mail to” hyperlink and safe “mail to” hyperlink function is:-

      Parameters:

    • $email (string) : E-mail address
    • $title (string) : Anchor title
    • $attributes (mixed) : HTML attributes
    • Returns : A “mail to” hyperlink and A spam-safe “mail to” hyperlink
    • Return type : string

    EXAMPLE

    Here is simple example of A “mail to” hyperlink and safe “mail to” hyperlink.

    A “mail to” hyperlink and safe “mail to” hyperlink in Codeigniter Example:-

    The output will be like this –

    Codeigniter URL Helper

    7. Linkified string

    This function is used to create link of email or url. It accepts three parameters- input string, type and popup. Syntax of Linkified string function is :-

    Syntax of Linkified string function is:-

      Parameters:

    • $str (string) : Input string
    • $type (string) : Link type (‘email’, ‘url’ or ‘both’)
    • $popup (bool) : Whether to create popup links
    • Returns : Linkified string
    • Return type : string

    EXAMPLE

    Here is simple example of Linkified string.

    Linkified string in Codeigniter Example:-

    The output will be like this –

    Codeigniter URL Helper

    8. URL-formatted string

    This Function is used to create a human friendly url strings. it accept three parameter-input string, seperetor(this is second parameter which is used to seperated a word) and lowercase (bool). Syntax of URL-formatted string function is:-

    Syntax of URL-formatted string function is:-

      Parameters:

    • $str (string) : Input string
    • $separator (string) : Word separator
    • $lowercase (bool) : Whether to transform the output string to lower-case
    • Returns : URL-formatted string
    • Return type : string

    EXAMPLE

    Here is simple example of URL-formatted string.

    URL-formatted string in Codeigniter Example:-

    The output will be like this –

    Codeigniter URL Helper

    9. Protocol-prefixed URL string

    This Function is used to added http tag in url and pass the url string to the function. Syntax of Protocol-prefixed URL string function is:-

    Syntax of Protocol-prefixed URL string function is:-

      Parameters:

    • $str (string) : url string
    • Returns : Protocol-prefixed URL string
    • Return type : string

    EXAMPLE

    Here is simple example of Protocol-prefixed URL string.

    Protocol-prefixed URL string in Codeigniter Example:-

    The output will be like this –

    Codeigniter URL Helper

    10. Redirect

    This Function is used to redirect url with base url. this function accept three parameters-uri strings, methods and code.Syntax of Redirect function is:-

    Syntax of Redirect function is:-

      Parameters:

    • $uri (string) : URI string
    • $method (string) : Redirect method (‘auto’, ‘location’ or ‘refresh’)
    • $code (string) : HTTP Response code (usually 302 or 303)
    • Return type : void

    EXAMPLE

    Here is simple example of Redirect.

    Redirect in Codeigniter Example:-

    The output will be like this –


    User Ans/Comments

    📖 Read More


Advertisements