Search code examples
phpcodeignitermethodshelperrequire-once

Which is safe, using required once or making one function in helper in codeigniter?


I had one problem while calling controller from another controller,one of the user of stackoverflow suggested to use require_once but another person said it's not a good idea now i'm confused, which is safe ? Using require_once or write a function in helper?

Old question link


Solution

  • I would say in general that calling a controller from within another controller is not a best practice. If two controllers need to use the same logic then maybe that logic should be in a separate place. This can be done by creating your own library and loading it within both controllers.

    Check out the link below to learn more about creating libraries in CodeIgniter.

    Creating Libraries