• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call Model function from Controller

#1
While I know the concept of MVC but I am not sure if I am doing this the most 'efficient' way
I have sql function in Model, I wan call it from Controller to pass it to View
Below is how I do the 'flow'.
Any shorter method or there a better way of doing?

Controller
PHP Code:
$participants = new ParticipantModel();
$data['participants_details'] = $participants ->participants_total();

echo view('login', $data); 


Model
PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
ParticipantModel extends Model
{
public function 
participants_total() {
// (some sql query here and return result)
}

Reply

#2
That's the right way to do it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.