Can anyone please explain me the object flow in codeigniter MVC ? I can see for example when I put the followong code in controller it works, but i am not being able to figure out which part of this goes in model in vews. I tried several ways but coudn't. When i use the example codes from other it works but myself i am getting confused. Please help
$query = $this->db->query("YOUR QUERY");
foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
开发者_如何学Go echo $row->body;
}
That would translate into something like:
Model:
class SomeModel extends Model {
function SomeModel() {
parent::Model();
}
function get_some_data() {
return $this->db->query('some_query')->result_array();
}
}
Controller:
class SomeController extends Controller {
function SomeController() {
parent::Controller();
}
function index() {
$this->load->model('SomeModel');
$some_data = $this->SomeModel->get_some_data();
$this->load->view('some_view');
}
}
View:
foreach($some_data as $data) {
echo $data->title;
echo $data->name;
echo $data->body;
}
However, for your communication between controller and view I would recommend using a template parser such as Dwoo or Twig (I don't like the one that comes with CI).
On the controller part I was doing:
class SomeController extends Controller {
function SomeController() {
parent::Controller();
}
function index() {
}
function show_data(){
$this->load->model('SomeModel');
$some_data = $this->SomeModel->get_some_data();
$this->load->view('some_view.php');
$this->index()
}
}
is that not the way to do it when we have many function ? When i look at other's code I see something like that or I am wrong ?
精彩评论