Is there a difference between the helper method and the library called in the code igniter?

I'm a little confused how the library and helper methods are used in a code igniter. I am still learning code igniter.

CONTROLLER

function index(){ $this->load->helper('text'); $this->load->library('auth'); //custom library $data['string'] = 'this is sample ..... this is sample'; $this->load->view('article', $data); } 

BROWSE

 <?php if(is_logged_in()){ //is_logged_in() is the method from the library, 'auth' echo 'You are logged in'; } <p><?php echo word_limiter($string, 10); ?></p> <!--word_limiter() is the method from the helper, 'text' --> 

In the above view file, the helper method word_limiter() works fine. But the is_logged_in() method does not work. But if I do this ( $this->auth->is_logged_in() ), it will work.

But why is the method from a helper, i.e. word_limiter() , no need to write like this ( $this->text->word_limiter() ).

Is there a difference between helper method and library?

+8
php codeigniter codeigniter-2 codeigniter-helpers
source share
2 answers

The CodeIgniter helper is a collection of related functions (common functions) that you could use in models, views, controllers, everywhere.

After downloading (including) this file, you can access the functions.

But the library is the class you need to make an instance of the class (via $this->load->library() ). And you will need to use the $this->... object to call the methods.

Typically, the thumb: The library is used in an object-oriented context (Controller, ...), and the assistant is more suitable for use in views (not object-oriented).

+20
source share

CI helper may or may not have a class

But the library must have a class representation.

Refer to this SO request

CodeIgniter: Making Decisions for Creating a Library and Helper in CodeIgniter

+3
source share

All Articles