CodeIgniter Helper

Next Page Previous Page

Hepler simplifies the collection of functions that help us to complete tasks, there are various types of helpers.

  • Array Helpers:

In PHP using arrays seems a lot of work to do, The array helper is created to make arrays more simple and very easy to manage without changing their core concept and functionalities.

Syntax:

helper('array');

Functions:

dot_array_search(string $search, array $values)

Parameters:

  • $search: how we will search the array.
  • $value: the array name that is supposed to be searched.

Example:

Array:


$data = [

    'Food' => [

        'Veg' => [

            'Paneer' => 150

        ],

        'Non-Veg' => [

            'Chicken' => 250

        ]

    ]

]


Function:

   $Paneer = dot_array_search('Food.Veg.Paneer', $data);

// this will return us the value of Paneer i.e. 150




  $Chicken = dot_array_search('Food.Non-Veg.Chicken, $data);

// this will return us the value of Chicken i.e. 250
  • Cookie Helper:

 

Cookie helper is responsible for all the functions related to cookies in our application.

Syntax:

helper('cookie');

Functions:

  • set_cookie()
Example:

set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = false[, $httpOnly = false]]]]]]])

Parameters:

  • $name - name contains a cookie name and can have all types of values. 
  • $value - cookie value holds the value of cookies in the form of string.
  • $expire - can only store integer value, i.e the time of expiration of the cookie.
  • $domain - Domain name of the cookie in a string.
  • $path - Path of the cookie in the form of string.
  • $prefix - the path of the cookie in the string form.
  • $secure - decides the cookie will be sent through HTTP or https.
  • $httpOnly - $httpOnly will hide our cookie from the java scripts.
  • get_cookie():
get_cookie($index[, $xss_Clean = false])

Parameters:

  • $name - name contains a cookie name and can have all types of values. 
  • $xss_clean (bool) – if we wish to apply the XSS filtering to our returned value with the help of boolean numbers.

 

  • delete_cookie():
delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]])

Parameters:

  • $name - name contains a cookie name and can have all types of values. 
  • $domain - Domain name of the cookie in a string.
  • $prefix - the path of the cookie in the string form.
  • $path - Path of the cookie in the form of string.

 

  • Date Helper:

Data helpers are responsible for the function that have operations related to the dates.

Syntax:

helper('date');

Function:

  • name():
now([$timezone = NULL])

Parameters:

  • $timezone – a string that contains the time zone.
  • timezone_select():
timezone_select([$class = '', $default = '', $what = DateTimeZone::ALL, $country = null])

Parameters:

  • $timezone – a string that contains the time zone.
  • $class  – this is optional, a string that can apply to the field.
  • $default  – default selection string value. 
  • $what  – integer that contains TimeZone.
  • $country  – a string of country code.

Example:

echo now('India/Mumbai’);

echo timezone_select('custom-select', 'India/Delhi’);
  • Filesystem Helper:

Filesystem Helper is responsible for all operations related to the files and  directories in our application.

Syntax:

helper('filesystem');

Functions in Filesystem Helper:

Function

Syntax

directory_map():

directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]])

write_file():

write_file($path, $data[, $mode = 'wb'])

delete_files():

delete_files($path[, $del_dir = FALSE[, $htdocs = FALSE]])

get_filenames():

get_filenames($source_dir[, $include_path = FALSE])

get_dir_file_info():

get_dir_file_info($source_dir, $top_level_only)

get_file_info():

get_file_info($file[, $returned_values = ['name', 'server_path', 'size', 'date']])

symbolic_permissions():

symbolic_permissions($perms)

octal_permissions():

octal_permissions($perms)

set_realpath():

set_realpath($path[, $check_existence = FALSE])

Example:

$map = directory_map('./mydirectory/');

write_file('./path/to/file.php', $data, 'r+');
  • Form Helper:

Form Helper is responsible for all operations related to the Form and  Form elements in our application.

Syntax:

 

helper('form');

Functions in Form Helper:

Function

Syntax

form_open():

form_open([$action = ''[, $attributes = ''[, $hidden = []]]])

form_open_multipart():

form_open_multipart([$action = ''[, $attributes = ''[, $hidden = []]]])

Form_hidden():

form_hidden($name[, $value = ''])

form_input():

form_input([$data = ''[, $value = ''[, $extra = ''[, $type = 'text']]]])

form_password():

form_password([$data = ''[, $value = ''[, $extra = '']]])

form_upload():

form_upload([$data = ''[, $value = ''[, $extra = '']]])

form_textarea():

form_textarea([$data = ''[, $value = ''[, $extra = '']]])

form_dropdown():

form_dropdown([$name = ''[, $options = [][, $selected = [][, $extra = '']]]])

form_multiselect():

form_multiselect([$name = ''[, $options = [][, $selected = [][, $extra = '']]]])

form_fieldset():

form_fieldset([$legend_text = ''[, $attributes = []]])

form_fieldset_close():

form_fieldset_close([$extra = ''])

form_checkbox():

form_checkbox([$data = ''[, $value = ''[, $checked = FALSE[, $extra = '']]]])

form_radio():

form_radio([$data = ''[, $value = ''[, $checked = FALSE[, $extra = '']]]])

form_label():

form_label([$label_text = ''[, $id = ''[, $attributes = []]]])

form_submit():

form_submit([$data = ''[, $value = ''[, $extra = '']]])

form_reset():

form_reset([$data = ''[, $value = ''[, $extra = '']]])

form_button():

form_button([$data = ''[, $content = ''[, $extra = '']]])

form_close():

form_close([$extra = ''])

set_value():

set_value($field[, $default = ''[, $html_escape = TRUE]])

set_select():

set_select($field[, $value = ''[, $default = FALSE]])

set_checkbox():

set_checkbox($field[, $value = ''[, $default = FALSE]])

set_radio():

set_radio($field[, $value = ''[, default = FALSE]])

 

  • Html Helper:

HTML Helper is responsible for all operations related to the HTML and  HTML elements in our application.

Syntax:

helper('form');

Functions of HTML Helper:

 

Function

Syntax

img()

img([$src = ''[, $indexPage = false[, $attributes = '']]])

link_tag()

link_tag([$href = ''[, $rel = 'stylesheet'[, $type = 'text/css'[, $title = ''[, $media = ''[, $indexPage = false[, $hreflang = '']]]]]]])

script_tag()

script_tag([$src = ''[, $indexPage = false]])

ul()

ul($list[, $attributes = ''])

ol()

ol($list, $attributes = '')

video()

video($src[, $unsupportedMessage = ''[, $attributes = ''[, $tracks = [][, $indexPage = false]]]])

audio()

audio($src[, $unsupportedMessage = ''[, $attributes = ''[, $tracks = [][, $indexPage = false]]]])

source()

source($src = ''[, $type = false[, $attributes = '']])

embed()

embed($src = ''[, $type = false[, $attributes = ''[, $indexPage = false]]])

object()

object($data = ''[, $type = false[, $attributes = '']])

param()

param($name = ''[, $type = false[, $attributes = '']])

track()

track($name = ''[, $type = false[, $attributes = '']])

doctype()

doctype([$type = 'html5'])

 

  • Inflector Helper:

Inflector helpers perform grammar functions in the English language with the help of various functions.

 

Syntax:

helper('inflector');

Function in Inflector Helper:

Function

Syntax

singular()

singular($string)

plural()

plural($string)

counted()

counted($count, $string)

camelize()

camelize($string)

pascalize()

pascalize($string)

underscore()

underscore($string)

humanize()

humanize($string[, $separator = '_'])

is_pluralizable()

is_pluralizable($word)

dasherize()

dasherize($string)

ordinal()

ordinal($integer)

ordinalize()

ordinalize($integer)

 

  • Number Helper:

Number helpers are responsible for all numeric data operations in the application.

 

Syntax:

helper('number');

Function in Number helper:

Function

Syntax

number_to_size()

number_to_size($num[, $precision = 1[, $locale = null])

number_to_amount()

number_to_amount($num[, $precision = 1[, $locale = null])

number_to_currency()

number_to_currency($num, $currency[, $locale = null])

number_to_roman()

number_to_roman($num)

 

  • Security Helper:

Security helpers are responsible for all Security related operations in the application.

Syntax:

helper('security');

Function in Security helper:

Function

Syntax

sanitize_filename()

sanitize_filename($filename)

strip_image_tags()

strip_image_tags($str)

encode_php_tags()

encode_php_tags($str)

 

  • Test Helper:

Test helpers are responsible for all testing related operations in the application.

Syntax:

helper('test');

Function in Test helper:

Function

Syntax

fake()

fake($model, array $overrides = null)

 

  • Text Helper:

Text helpers are responsible for all text-related operations in the application.

Syntax:

helper('text');

Function in Text helper:

Function

Syntax

random_string

random_string([$type = 'alnum'[, $len = 8]])

increment_string

increment_string($str[, $separator = '_'[, $first = 1]])

alternator

alternator($args)

reduce_double_slashes

reduce_double_slashes($str)

strip_slashes

strip_slashes($data)

reduce_multiples

reduce_multiples($str[, $character = ''[, $trim = FALSE]])

quotes_to_entities

quotes_to_entities($str)

strip_quotes

strip_quotes($str)

word_limiter

word_limiter($str[, $limit = 100[, $end_char = '…']])

character_limiter

character_limiter($str[, $n = 500[, end_char = '…']])

ascii_to_entities

ascii_to_entities($str)

entities_to_ascii

entities_to_ascii($str[, $all = TRUE])

convert_accented_characters

convert_accented_characters($str)

word_censor

word_censor($str, $censored[, $replacement = ''])

highlight_code

highlight_code($str)

highlight_phrase

highlight_phrase($str, $phrase[, $tag_open = '<mark>'[, $tag_close = '</mark>']])

word_wrap

word_wrap($str[, $charlim = 76])

ellipsize

ellipsize($str, $max_length[, $position = 1[, $ellipsis = '&hellip;']])

excerpt

excerpt($text, $phrase = false, $radius = 100, $ellipsis = '...')

 

  • URL Helper:

URL helpers are responsible for all URL related operations in the application.

 

Function in URL helper:

Function

Syntax

site_url()

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

base_url()

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

current_url()

current_url([$returnObject = false])

previous_url()

previous_url([$returnObject = false])

uri_string()

uri_string()index_page([$altConfig = NULL])

anchor()

anchor([$uri = ''[, $title = ''[, $attributes = ''[, $altConfig = NULL]]]])

anchor_popup()

anchor_popup([$uri = ''[, $title = ''[, $attributes = FALSE[, $altConfig = NULL]]]])

mailto()

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

safe_mailto()

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

auto_link()

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

url_title()

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

mb_url_title()

mb_url_title($str[, $separator = '-'[, $lowercase = FALSE]])

prep_url()

prep_url($str = '')



  • XML Helper:

XML helpers are responsible for all XML related operations in the application.

 

Syntax:

helper('xml');

Function in XML helper:

Function

Syntax

xml_convert()

xml_convert($str[, $protect_all = FALSE])

 

Next Page Previous Page

Treding Tutorial

Popular Tutorials

to Learn now