【发布时间】:2012-01-14 21:11:42
【问题描述】:
对于我目前的项目,我决定为一些常用功能创建一个库。
例如:Login_check、get_current_user 等
根据我的知识,我创建了一个简单的,但不幸的是它不起作用。
这是我的图书馆:
文件名:Pro.php,位于application/libraries
class Pro{
public function __construct()
{
parent::_construct();
$CI =& get_instance();
$CI->load->helper('url');
$CI->load->library('session');
$CI->load->database();
}
function show_hello_world()
{
$text = "Hello World";
return $text;
}
}
?>
我试图将它加载到我的控制器上:
<?php
class Admin extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library(array('session'));
$this->load->library("Pro");
}
function index()
{
echo($this->Pro->show_hello_world());
}
}
?>
我看不到任何错误...但我得到一个空白页。
我怎么了??
谢谢。
编辑:我收到了这个错误:
Call to a member function show_hello_world() on a non-object in C:\wamp\www\Project\application\controllers\admin.php on line 13
【问题讨论】:
-
@Hary 没有错误,我得到一个空白页。
-
在第 13 行调用 C:\wamp\www\project\application\controllers\admin.php 中非对象的成员函数 show_hello_world()
-
@Hary
echo($this->Pro->show_hello_world()); -
@DileepDil 您是否在我的回答中完全尝试了整个测试用例? (我已经更新了一点)
-
@DamienPirsy 是的,我做到了...现在我正在下载 codeigniter [新鲜的]
标签: php class codeigniter