我刚刚获得了如何访问函数中的函数的帮助。现在我尝试从内部函数到达一个在构造函数中为intitade的库。
我的代码如下:
<?php
class Test_model extends CI_Model
{
private $ci;
function __construct()
{
parent::__construct();
// Initiate instance
$ci =& get_instance();
// Load helper
$ci->load->helper('text');
}
public function check()
{
echo $this->uniqueString();
}
public function uniqueString($unique = FALSE)
{
function random()
{
return parent::random_string('alnum',20);
}
while($unique === FALSE)
{
$random = random();
$this->db->where('ver_code', $random);
$this->db->from('user');
if($this->db->count_all_results() == 0)
{
return $random;
$unique = TRUE;
}
}
}
}
?>
但是我无法从函数随机到达库助手。我试过了
parent::random_string('alnum',20);
$ci->random_string('alnum',20);
$this->ci->random_string('alnum',20);
random_string('alnum',20);
我收到的错误如下:
Call to undefined method Test_model::random_string()
Cannot access self:: when no class scope is active in
Using $this when not in object context in
如何正确地做到这一点?