Codeigniter:在模型和控制器、模型和模型、控制器和控制器之间使用变量的最简单方法

发布于 2024-10-08 21:36:58 字数 350 浏览 0 评论 0原文

难道这根本不可能吗?

我想我应该清理一些代码,并将数据库查询仅放入它们所属的模型中,并将属于控制器中的所有其他代码放入控制器中。

现在我不断收到未定义的变量错误。这不是问题,但我正在尝试找出如何在文件之间调用变量。

我只是想将注册时生成的随机哈希存储在变量中,因为这是我在发送到用户电子邮件的“单击此处激活帐户”链接的锚点中使用的变量。

我还在方法中使用相同的变量,将电子邮件中 ​​URL 末尾的 uri 哈希与数据库中存储的 uri 哈希进行比较。以便用户确认其帐户并将数据库中的“状态”更新为 1 (活性)。

我真的很感激一些建议。我很享受这个学习过程。睡眠不足,但很享受它,因为它让我进行逻辑思考。

Is this just impossible?

I thought I would clean up some of my code 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贪恋 2024-10-15 21:36:58

如果变量位于单独的文件中,则无法访问该变量,而应该在类中设置它。

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;
    }
}

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文