CodeIgniter notes #2

A controller page may looks like this

This is a controller named home, the home must be spelled in capital letter. When a person views your website at index.php/home, it will lead to this controller. At the index function, we may include

This will loads the view called home_view and passed in the value of $data.

The home_view.php view page may looks like this.

It is html will php, view displays the page, so it is normal to expect html code in view.

To deal with database, we may include this line in the controller.

The first line loads the model/ database called ecommerce_product in the model/admin folder. Then, it will call the function getLatestProducts on the model and store the data in $data[‘latestProd’]. This is how we interact with database from the controller.

The ecommerce_product model may looks like this.

In the getLatestProductsfunction, we can call query to sql by executing:

Leave a Reply