CodeIgniter Forums
Include model inside a model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Include model inside a model (/showthread.php?tid=79450)



Include model inside a model - LuxesR - 06-18-2021

Hello! We are finally ready to use CodeIgniter 4. I only have some problems with using a model inside a model. I was expecting that I could use something like this:

PHP Code:
namespace App\Models;
use 
CodeIgniter\Model;
class 
Filters_model extends Model {

    function __construct(){
        // Call the Model constructor
        parent::__construct();
        $this->session session();
        $this->customers model('Customers_model');
    }



But that doesn't seems to work. I'm getting a "Service Temporarily Unavailable" error. In CI3 you could just put it in autoload and use it wherever you like.

How can I include a model inside a current model to use those functions of that model?


RE: Include model inside a model - MGatner - 06-19-2021

Conceptually that should work fine! I believe your actual error is hiding because you are in a production instance. Try checking your error logs or switching the environment to “development” and share the actual issue.


RE: Include model inside a model - LuxesR - 06-19-2021

(06-19-2021, 06:12 AM)MGatner Wrote: Conceptually that should work fine! I believe your actual error is hiding because you are in a production instance. Try checking your error logs or switching the environment to “development” and share the actual issue.

Thanks for your reply. I've checked in the index.php. The environment is in development.


RE: Include model inside a model - paliz - 06-19-2021

Rename env file to. env


CI_ENVIRONMENT = production

To development

Remove # too