抱歉问了这个愚蠢的问题,但这让我发疯了......
我的 test_framework.php 如下:
<?php
class Test_framework extends CI_Controller{
function display_test(){
echo "loading model...";
$this -> load -> model('test_model');
echo "model loaded...";
}
}
?>
和test_model.php如下:
<?php
class Test_model extends Model {
function get_all(){
$q = $this -> db -> query("SELECT * FROM users");
foreach($q -> result() as $row)
{
$data[] = $row;
}
return $data;
}
}
?>
当我转到index.php/test_framework/display_test时,我看到“正在加载模型...”,但从未看到“模型已加载...”,并且没有错误(只是一个空白的白页)。这里可能发生了什么问题??
最佳答案
嗯,首先,你的类命名是错误的。此外,您必须扩展父模型 __construct();
在这里您可以设置回显来跟踪模型的加载:
class Test_model extends CI_Model {
function __construct()
{
parent::__construct();
echo 'Model loaded!'; // something like this
}
function get_all()
{
// your code here
}
}
编辑:引用manual :
Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.
基本原型(prototype)(来自手册)是:
class Model_name extends CI_Model {
function __construct()
{
parent::__construct();
}
}
如果您想记录 Controller 和模型等的初始化,而不是让它们在您的页面上回显某些内容,您可以在 application/config.php 中启用日志记录:
$config['log_threshold'] = 1;
// 0 = Disables logging, Error logging TURNED OFF
// 1 = Error Messages (including PHP errors)
// 2 = Debug Messages
// 3 = Informational Messages
// 4 = All Messages
关于php - 简单代码点火器错误...加载->模型无提示失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6416040/