Can you access a model from inside another model in CodeIgniter?(您可以从 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 中的另一个模型内部访问模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您可以从 CodeIgniter 中的另一个模型内部访问模型吗?
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
