您可以从codeIgniter另一个模型内部访问一个模式? [英] Can you access a model from inside another model in CodeIgniter?

查看:109
本文介绍了您可以从codeIgniter另一个模型内部访问一个模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写使用codeIgniter需要身份验证的Web应用程序。我创建了处理我所有的验证模型。但是,我无法找到一个方法来从另一个模型内部访问此身份验证模型。有没有办法从内部其他模式进入一种模式,或者有更好的方式来处理codeIgniter内部认证?

I am writing a webapp using CodeIgniter that requires authentication. I created a model which handles all my authentication. However, I can't find a way to access this authentication model from inside another model. Is there a way to access a model from inside another mode, or a better way to handle authentication inside CodeIgniter?

推荐答案

在一般情况下,你不希望创建一个对象内部的对象。这是一个不好的习惯,而是写一个清晰的API和注入模型到模型。

In general, you don't want to create objects inside an object. That's a bad habit, instead, write a clear API and inject a model into your model.

<?php
// in your controller
$model1 = new Model1();
$model2 = new Model2();
$model2->setWhatever($model1);
?>

这篇关于您可以从codeIgniter另一个模型内部访问一个模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆