CodeIgniter Helper Functions
Jamshid Hashimi
Trainer, Cresco Solution
http://www.jamshidhashimi.com
jamshid@netlinks.af
@j...
Agenda
• Array Helper
• Directory Helper
• Download Helper
• Email Helper
• File Helper
• Form Helper
• HTML Helper
• Text...
Array Helper
• The Array Helper file contains functions that assist in
working with arrays.
• $this->load->helper('array')...
Directory Helper
• The Directory Helper file contains functions
that assist in working with directories.
• $this->load->he...
Download Helper
• The Download Helper lets you download data to
your desktop.
• $this->load->helper('download');
– Loading...
Email Helper
• The Email Helper provides some assistive
functions for working with Email.
• $this->load->helper('email');
...
File Helper
• The File Helper file contains functions that assist in working
with files.
• $this->load->helper('file');
– ...
File Helper
• get_filenames('path/to/directory/')
– Takes a server path as input and returns an array
containing the names...
File Helper
• get_mime_by_extension('file')
– Translates a file extension into a mime type based on
config/mimes.php.
• sy...
Form Helper
• The Form Helper file contains functions that assist in
working with forms.
• $this->load->helper('form');
– ...
Form Helper
• form_hidden()
– Lets you generate hidden input fields.
• form_input()
– Lets you generate a standard text in...
HTML Helper
• The HTML Helper file contains functions that assist in working with HTML.
• $this->load->helper('html');
– L...
Text Helper
• The Text Helper file contains functions that assist in working with
text.
• $this->load->helper('text');
– L...
URL Helper
• The URL Helper file contains functions that assist in working with URLs.
• $this->load->helper('url');
– Load...
URL Helper
• anchor()
– Creates a standard HTML anchor link based on your local site
URL
• anchor_popup()
– Nearly identic...
DEMO
QUESTIONS?
Upcoming SlideShare
Loading in …5
×

CodeIgniter Helper Functions

2,120 views
1,976 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,120
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
51
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

CodeIgniter Helper Functions

  1. 1. CodeIgniter Helper Functions Jamshid Hashimi Trainer, Cresco Solution http://www.jamshidhashimi.com jamshid@netlinks.af @jamshidhashimi ajamshidhashimi Afghanistan Workforce Development Program
  2. 2. Agenda • Array Helper • Directory Helper • Download Helper • Email Helper • File Helper • Form Helper • HTML Helper • Text Helper • URL Helper
  3. 3. Array Helper • The Array Helper file contains functions that assist in working with arrays. • $this->load->helper('array'); – Loading helper • element() – Lets you fetch an item from an array. • random_element() – Takes an array as input and returns a random element from it. • elements() – Lets you fetch a number of items from an array.
  4. 4. Directory Helper • The Directory Helper file contains functions that assist in working with directories. • $this->load->helper('directory'); – Loading helper • directory_map('source directory') – This function reads the directory path specified in the first parameter and builds an array representation of it and all its contained files.
  5. 5. Download Helper • The Download Helper lets you download data to your desktop. • $this->load->helper('download'); – Loading the helper • force_download('filename', 'data') – Generates server headers which force data to be downloaded to your desktop. Useful with file downloads. The first parameter is the name you want the downloaded file to be named, the second parameter is the file data.
  6. 6. Email Helper • The Email Helper provides some assistive functions for working with Email. • $this->load->helper('email'); – Loading helper • valid_email('email') – Checks if an email is a correctly formatted email. Note that is doesn't actually prove the email will recieve mail, simply that it is a validly formed address.
  7. 7. File Helper • The File Helper file contains functions that assist in working with files. • $this->load->helper('file'); – Loading helper • read_file('path') – Returns the data contained in the file specified in the path. • write_file('path', $data) – Writes data to the file specified in the path. If the file does not exist the function will create it. • delete_files('path') – Deletes ALL files contained in the supplied path. – If the second parameter is set to true, any directories contained within the supplied root path will be deleted as well.
  8. 8. File Helper • get_filenames('path/to/directory/') – Takes a server path as input and returns an array containing the names of all files contained within it. • get_dir_file_info('path/to/directory/', $top_level _only = TRUE) – Reads the specified directory and builds an array containing the filenames, filesize, dates, and permissions. • get_file_info('path/to/file', $file_information) – Given a file and path, returns the name, path, size, date modified.
  9. 9. File Helper • get_mime_by_extension('file') – Translates a file extension into a mime type based on config/mimes.php. • symbolic_permissions($perms) – Takes numeric permissions (such as is returned by fileperms() and returns standard symbolic notation of file permissions. • octal_permissions($perms) – Takes numeric permissions (such as is returned by fileperms() and returns a three character octal notation of file permissions.
  10. 10. Form Helper • The Form Helper file contains functions that assist in working with forms. • $this->load->helper('form'); – Loading Helper • form_open() – Creates an opening form tag with a base URL built from your config preferences. – $attributes = array('class' => 'email', 'id' => 'myform'); – $hidden = array('username' => 'Joe', 'member_id' => '234'); • form_open_multipart() – This function is absolutely identical to the form_open() tag above except that it adds a multipart attribute, which is necessary if you would like to use the form to upload files with.
  11. 11. Form Helper • form_hidden() – Lets you generate hidden input fields. • form_input() – Lets you generate a standard text input field. • form_password() • form_upload() • form_textarea() • form_dropdown() – Lets you create a standard drop-down field. • form_checkbox() – Lets you generate a checkbox field. • form_radio() • form_submit() • form_reset() • form_button() • form_close()
  12. 12. HTML Helper • The HTML Helper file contains functions that assist in working with HTML. • $this->load->helper('html'); – Loading helper • br() – Generates line break tags (<br />) based on the number you submit. • heading() – Lets you create HTML <h1> tags. The first parameter will contain the data, the second the size of the heading. • img() – Lets you create HTML <img /> tags. The first parameter contains the image source. • nbs() – Generates non-breaking spaces (&nbsp;) based on the number you submit.
  13. 13. Text Helper • The Text Helper file contains functions that assist in working with text. • $this->load->helper('text'); – Loading helper • word_limiter() – Truncates a string to the number of words specified. • character_limiter() – Truncates a string to the number of characters specified. • highlight_code() – Colorizes a string of code (PHP, HTML, etc.). • word_wrap() – Wraps text at the specified character count while maintaining complete words.
  14. 14. URL Helper • The URL Helper file contains functions that assist in working with URLs. • $this->load->helper('url'); – Loading helper • site_url() – Returns your site URL, as specified in your config file. • base_url() – Returns your site base URL, as specified in your config file. • current_url() – Returns the full URL (including segments) of the page being currently viewed. • uri_string() – Returns the URI segments of any page that contains this function. • index_page() – Returns your site "index" page, as specified in your config file.
  15. 15. URL Helper • anchor() – Creates a standard HTML anchor link based on your local site URL • anchor_popup() – Nearly identical to the anchor() function except that it opens the URL in a new window. • mailto() – Creates a standard HTML email link. • url_title() – Takes a string as input and creates a human-friendly URL string. • redirect() – Does a "header redirect" to the URI specified.
  16. 16. DEMO
  17. 17. QUESTIONS?

×