Welcome Guest, Not a member yet? Register   Sign In
Grocery Crud custom model with CI4
#1

Hi!

I want to implement a custom model from Grocery Crud but I see that CI4 does not have `get_instance` anymore. As per the example I need to do:
```
<?php
//CustomersModel.php

use GroceryCrud\Core\Model;
use GroceryCrud\Core\Model\ModelFieldType;

class CustomersModel extends Model {

    protected $ci;
    protected $db;

    function __construct($databaseConfig) {
        $this->setDatabaseConnection($databaseConfig);

        $this->ci = & get_instance();
        $this->db = $this->ci->db;
    }

    public function getFieldTypes($tableName)
    {
     ...
```

The question is, how may I get a CI4 context as this example is for CI3?
Example website: https://www.grocerycrud.com/docs/custom-model
Thank you.
Reply
#2

Why is this post under moderation?
Reply
#3

Use service("codeigniter")
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#4

All new users are under moderation.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB