如何引用实例化类
目前我有我的控制器实例化一个模型类。每次创建此类时,我都需要在模型中设置登录用户的信息。我觉得有一种更优雅的方法可以做到这一点,但我不确定如何做到这一点:-(
这是代码示例:
$leadModel = new Application_Model_DbTable_Leads;
$leadModel->user = $this->user;
我想从我正在创建的模型内部做的是访问用户使用类似的东西(我知道这仅适用于扩展其他类的类):
$user_id = $this::parent->user;
非常感谢!
Currently I have my controller instantiating a model class. Every time I create this class I need to set the logged in user's info in the model. I feel like there is a more elegant way of doing this, but I'm not sure how to do it :-(
Here is an example of the code:
$leadModel = new Application_Model_DbTable_Leads;
$leadModel->user = $this->user;
What I would like to do from inside the model I'm creating is access the user using something like this (I know this only applies to classes that are extending other classes):
$user_id = $this::parent->user;
Thanks so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这通常是使用构造函数参数来完成的:
无法获取对实例化类的引用。
This is usually done using a constructor parameter:
There is no way to get a reference to the instantiating class.