Welcome Guest, Not a member yet? Register   Sign In
CI4 use model's method in view
#4

(06-21-2020, 10:56 AM)Digital_Wolf Wrote:
(06-21-2020, 07:06 AM)pippuccio76 Wrote: Hi ,sorry for engish , in ci3 if i have a model call codeigniterModel with a method call findById($id) 

in controller i load model with :

PHP Code:
$this->load->model('codeigniterModel'


and in view i can use   $this->codeigniterModel->findById($id) method 

how can i do the same on ci4 ?


Hello !

You can do it like this:
PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

// use u model class.
use App\Models\codeigniterModel;

class 
MyController extends Controller
{
    public function index()
    {
        // create instance u model.
        $CI_Model = new codeigniterModel();

        // call the method from model
        echo $CI_Model->findById($id);
    

p.s. Sorry my English.
I want use in a view not in a controller....
Reply


Messages In This Thread
CI4 use model's method in view - by pippuccio76 - 06-21-2020, 07:06 AM
RE: CI4 use model's method in view - by pippuccio76 - 06-21-2020, 11:15 AM
RE: CI4 use model's method in view - by InsiteFX - 06-22-2020, 03:06 AM
RE: CI4 use model's method in view - by InsiteFX - 06-22-2020, 08:13 AM
RE: CI4 use model's method in view - by jreklund - 06-22-2020, 01:58 PM
RE: CI4 use model's method in view - by jinbatsu - 08-21-2020, 09:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB