php - 如何在库 codeigniter 上调用私有(private)方法

标签 php codeigniter

我有一个名为 privacy 的库,我将一个名为 _user_block_by_team 的函数设为私有(private) 我想像下面的代码一样在同一个库的另一个公共(public)函数上调用这个函数,但它给我一个错误 Fatal error: Call to undefined method Team::_user_block_by_team() 我在哪里做错了吗?该库从文件 autoload.php 自动加载

class Privacy {

    function __construct()
    {
        $this->ci =& get_instance();    
    }

    function user_block_team($id_user) {
        $this->ci->_user_block_by_team($id_user);
    }

    function _user_block_by_team($id_user) {
        $this->ci->load->library('settings');
        if ($this->ci->settings->check_user_blocked($id_user)) {
            return false;
        }

        return true;
    }
}

最佳答案

你可以调用$this->_user_block_by_team($id_user)

关于php - 如何在库 codeigniter 上调用私有(private)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19428741/

相关文章:

php - 将 JOIN SQL 查询序列化为 JSON 的最佳方法

php - 如何将数据库表转换为 Doctrine 实体

php - 为什么我的 bootstrap.min.css 文件没有在 codeigniter 中加载

php - 检查是否超过 18 年,仅适用于 1960->1994

javascript - 如何在php中将日期和时间格式化为CRON格式?

php - 在 CodeIgniter 的 Active Record 中使用 'having'

php - sql查询多表查询问题

Codeigniter php7 错误

php - 在 CodeIgniter 中为 ( :any)

php - 想要使用 php mysql 在水平表中显示结果