Codeigniter: easiest way to use variables between models and controllers, models and models, controllers and controllers
Is this just impossible?
I thought I would clean up some of my code开发者_如何学Go and put db queries in models only where they belong and put all the other code that belongs in controllers in controllers.
Now I keep getting undefined variable errors. Which is not a problem but I'm trying to work out how to call variables between files.
I would simply like the random hash generated at registration .. stored in a variable because that's the variable I use in the anchor for the "click here to activate account" link that is sent to users email.
I also use that same variable in the method that compares the uri hash that's at the end of the URL in their email with the one stored in the database.. in order for user to confirm their account and update "status" in database to 1(activated).
I would really appreciate some advice. I'm enjoying this learning process. Loosing sleep but enjoying it as it make me think logically.
You cannot access a variable if it's in a seperate file, instead you should 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;
}
}
精彩评论