Just stared learning CodeIgniter (using v3.1.7). I have this table called training.
I followed the steps described in this tutorial:
First, create a model called training_model.php (put it in /application/models)
<?php
class training_model extends CI_Model {
function get_all_trainings(){
$q = $this->db->get('training');
if($q->num_rows() > 0){
foreach ($q->result() as $row){
$data[] = $row;
}
return $data;
}
}
?>
Then create it's controller (training.php), put in /application/controllers.
<?php
if(!defined("BASEPATH")) exit("No direct script access allowed");
class training extends CI_Controller
{
public function index()
{
$this->load->model("training_model");
$data["trainings"]=$this->users_model->get_all_trainings();
$this->load->view("users_view", $data);
}
}
Last one is the view (training_view.php), put it into /application/views
<?php
if (!empty($trainings)){
foreach ($trainings as $t){
echo $t->eventName .' '. $t->eventDescription.' '.$t->eventDate.' '.$t->eventVenue;
}
}
?>
How to access the view from the browser, so I can see the database's content?