RE: How will you call a constructor in CodeIgniter?

How will you call a constructor in CodeIgniter?

debjit Default Asked on June 7, 2018 in CODEIGNITER.
Add Comment
1 Answers

Anyway, yes, the magic method __construct() is called (automatically) upon each instantiation of the class,

Usually, in CI is not necessary to call a constructor, unless you actually want one. You can alternatively put the library/helper/model you want to have alywas loaded in the respective autoload array in config/autoload.php (check “autoloading” in CI’s manual)

Once you define a constructor in your child Controller you’re compelled to call the parent constructor (of the mail CI_Controller class), because there is where the main CI object is created and all the classes are loaded, and you need those in your child controller too; if fail to do so your child class will construct separately and won’t inherit.

Senior Developer Answered on July 3, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.