Codeigniter: the easiest way to use variables between models and controllers, models and models, controllers and controllers

Is it just not possible?

I thought I could clear part of my code and put the db queries in the model only where they belong, and put all the other code that belongs to the controllers in the controllers.

Now I keep getting undefined variables. This is not a problem, but I am trying to decide how to call variables between files.

I just would like the random hash generated during registration to be stored in a variable, because the variable that I use in the link is click here to activate the account, which is sent to users via email.

I also use the same variable in the method, which compares the uri hash code, which is stored in the database at the end of the URL in the email .. so that the user can confirm their account and update the “status” in the database to 1 (activated).

I would really appreciate some advice. I like this learning process. Losing sleep, but enjoying it as it makes me think logically.

+3
source share
1 answer

You cannot access a variable if it is in a separate file, instead you must set it in your class.

class User_model extends Model {

    // Declare the foo variable
    public $foo = "";

    function blah() {

        // You can set variable foo this way from any controller/model that includes this model
        $this->foo = "dog";

        // You can access variable foo this way
        echo $this->foo;
    }
}
+5
source

Source: https://habr.com/ru/post/1781963/


All Articles