我们如何在codeigniter中实现全局功能?

时间:2017-09-14 05:59:08

标签: php codeigniter-3

我向大家询问,我想在codeigniter中全局制作以下函数:

 $ci =& get_instance();

我有一个致命的错误:

Fatal error: Uncaught Error: Using $this when not in object context:

我想将$ ci用于$ this但我怎么能提到$ ci =& get_instance()全局?

我必须把$ ci =& get_instance();每个函数和每个文件中的代码。 请帮忙。

这是我的测试代码:

    public static function index()
    {   
    $ci =& get_instance();
    $redirect   = $ci->auth->is_logged_in(false, false);
    }

2 个答案:

答案 0 :(得分:0)

解决:

问题是php版本:

旧版

$this->employees_model->get_all();

新版

$ci =& get_instance();
$ci->employees_model->get_all();

答案 1 :(得分:0)

你可以创建帮助...因为你可以使用$ ci =&创建函数get_instance(); &安培;直接在控制器,模型,视图等中访问它。

Using Windows 10, Virtual Box 5.1.26, After trying almost all solutions and documenting them, Finally the following worked.

 1. Close The Virtual Box
 2. Change the maximum values for virtual box under File > Preferences > Display to Hint, 1366, 768;
 2. Go to C:\Users\{username}\.VirtualBox. Replace {username} with the logged in user
 3. Open VirtualBox.xml in an editor and append
   <ExtraDataItem name="CustomVideoMode1" value="1366x768x32"/>
  After 
    <ExtraData>
 4. Go to C:\Users\{username}\VirtualBox VMs\Ubuntu
 5. Open Ubuntu.vbox (Replace Ubuntu with the name of your virtual machine) in an editor and append
	<ExtraDataItem name="CustomVideoMode1" value="1366x768x32"/>
  After 
    <ExtraData>
	
 6. Close the editor and start the Virtual Box.
 7. Once Ubuntu starts, go to terminal type and change to root
    sudo vi /etc/default/grub
 8. Locate 
		GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
 9. Modify it to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyper_fb:1366x768x32"
 10. Close the file and run sudo update-grub
 11. Reboot the virtual machine instance.