Welcome Guest, Not a member yet? Register   Sign In
How to load a model in Autoload file
#1

How can I load a model in ...\app\Config\Autoload.php?

PHP Code:
namespace Config;

use 
CodeIgniter\Config\AutoloadConfig;

class 
Autoload extends AutoloadConfig {

    public function __construct() {
         
//load here
         //i've tried,
         
$my_model = new \App\Models\My_model();
 
        $my_model model("App\Models\My_model");
    

Nothing is working.

What is the correct way? Looking for help.
Thanks in advance.
Reply
#2

You should be able to load it using the ClassMap.

PHP Code:
$classmap = [
    'Markdown' => APPPATH 'third_party/markdown.php'
]; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 04-11-2021, 01:59 PM by ciddict.)

@InsiteFX, I didn't get it from your answer. Can you please be more specific?
Reply
#4

Why push the model to autoload?
The Autoload class is a tool for defining class file paths and including. It is not for loading classes directly.
Reply
#5

@iRedds, so there has no way to get a model in autoload class?
Reply
#6

Аbsolutely.
Tell me why are you trying to do this?
Reply
#7

I want to push some data to $psr4 variable dynamically. And I've to get that data from model.
How could I do that?
Reply
#8

Yes, you can add values dynamically.
But you won't create an instance of the model.

Take a look at the event documentation.
https://codeigniter.com/user_guide/exten...vents.html
Reply
#9

@iRedds, OK. Thanks.
Reply
#10

@iRedds, Can you please let me know how could I do that?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB