• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI4 use model's method in view

#11
You need to assign the complete model to a variable.

PHP Code:
<?php namespace App\Controllers;

use 
App\Models\ExampleModel;

class 
Example extends BaseController
{
    public function 
example()
    {
        
$exampleModel = new ExampleModel();

        
$data = [
            
'exampleModel' => $exampleModel,
        ];

        echo 
view('example'$data);
    }


You can then access it with $exampleModel->findbyid() in your view.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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