How do I use "include/require" in Codeigniter the right way?

Asked

Viewed 1,892 times

2

I’m migrating from the PHP to the CodeIgniter, and would like to know, how to use the include or require right in my code?

  • 1

    The same way I would use PHP pure. There is no different way to do this in the Codeigniter. But if your question applies to a context, show the context. Depending on what it is, you may not even need a include, and yes of a library, or a helper.

  • 1

    It depends on what you intend to do, but, Codeigniter is a framework written in PHP, the difference is none, but, the way to do this is different for sure, show examples !!!?

2 answers

3

Hello. The answer marked as correct does not respond to when the person really needs to do a include or require.

For those looking for a way to include a PHP (in this case a library), even knowing the MVC structure, follows:

require_once(APPPATH.'libraries/minhaLibraryAqui.php');

3


Most things you will use the load class of Codeigniter. For example:

$this->load->library('usuarios_class');
$this->load->view('usuarios/index-view');
$this->load->model('usuarios_model');

You can take a look at the Loader class here: Loader Class - Codeigniter.

It is important to aim for you to understand more or less how the MVC (Model, View, Controller) structure works. Understanding this, you can separate the functions of each and, using the Loader class, call everything you need.

  • Thank you, great Reply. I saw that you can also make the famous "Include" here $this->load->view('header'); $this->load->view('body'); $this->load->view('footer');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.