我有一个在生产环境中运行的codeigniter Web应用程序。 我正在尝试设置一个新的开发框,并复制了所有文件,并试图启动并运行它。到目前为止,这是不行的!当我提交页面/数据请求时...我得到一个 200 ...但 JSON 数据不会显示在页面上。
法典
以下是正在执行的"小部件"控制器代码:
public function getlocations()
{
echo("made it here");
exit;
$data = $this->rh_model->get_locations();
header ('Content-Type: application/json; charset=UTF-8');
echo json_encode($data);
// $this->output->enable_profiler(TRUE);
}//getlocations
到目前为止我尝试过什么
如您所见,我一直在玩代码以查看是否调用了该方法。
模型方法"get_locations"调用数据库并请求数据。 我已经从命令提示符确保我可以使用应用程序使用的相同凭据手动连接到数据库 - 如我的/var/www/html/rhAPI/application/config/database.php 文件中定义的那样。
以下是/var/log/apache2/access.log 显示的内容:
127.0.0.1 - - [10/Dec/2014:11:16:13 -0500] "GET/rhAPI/index.php/widgets/getlocations HTTP/1.1" 200 225 "-" "Mozilla/5.0 (X11;Linux x86_64( AppleWebKit/537.36 (KHTML, like 壁虎( 铬/39.0.2171.71 野生动物园/537.36" 127.0.0.1 - - [10/Dec/2014:11:16:28 -0500] "GET/rhAPI/index.php/widgets/getlocations HTTP/1.1" 200 225 "-" "Mozilla/5.0 (X11;乌班图;Linux x86_64;rv:34.0( 壁虎/20100101 火狐/34.0">
apache2 错误日志中没有任何内容。
浏览器调试工具中的"网络"部分在"标头"选项卡中显示 200 OK 状态代码,但"响应"选项卡为空。
文件权限。 我确保我所有的文件夹都有 755 个,文件是 644 个。 我不认为这是权限问题,因为当我故意错误地设置权限时,权限错误确实会显示在网页上。我的 php.ini 设置设置为显示所有错误消息的错误。
不确定我还能检查什么。任何建议将不胜感激。
编辑 1
我刚刚在开发盒上尝试了这个测试:
- 在/var/www/html 下创建一个名为"test"的新文件夹
使用以下代码创建一个名为 phpinfo.php 的新 PHP 文件:
- 试图导航到本地主机/测试/phpinfo.php但我在那里也没有得到任何东西。
现在我怀疑 apache2 设置了...检查。。。
编辑 2
我已将以下条目添加到模型中的构造函数中
public function __construct()
{
echo("in the constructor");
parent::__construct();
$this->load->database();
echo("loaded");
}
打印第一个调试语句,但不打印第二个调试语句。这是我在数据库中的内容.php:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'test1234';
$db['default']['database'] = 'testdb';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
这是我通过命令行执行的操作,以测试数据库连接是否正常工作:
me@medev:/var/www/html/rhAPI/application/models$ mysql -u root -p testdb
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or 'g.
Your MySQL connection id is 53
Server version: 5.6.19-1~exp1ubuntu2 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or ''h' for help. Type ''c' to clear the current input statement.
mysql>
我是个白痴。 我在这个新服务器上缺少 php5 mysql 驱动程序/包。我不得不:
sudo apt-get install php5-mysql
sudo service apache2 restart
我所有的问题都消失了。 对不起,噪音。