Reputation: 562
I have the following code in helloworld.php:
<?php
class Helloworld extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->model("helloworld_model");
$data["result"] = $this->Helloworld_model->getData();
$data["page_title"] = "CI Helloworld appis";
$this->load->view("helloworld_view", $data);
}
}
?>
The code stops executing after calling the parent constructor, without giving absolutely any error messages. Nothing appears in /var/log/apache2/error.log either. If I echo something before constructor call, it is echoed. If I type gibberish before the constructor call, a proper error message is printed. Why is this happening?
The site is running on Ubuntu server 12.04 with Code Igniter 2.1.4. and PHP 5.3.
Other files are helloworld_model.php:
<?php
class Helloworld_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function getData()
{
$query = $this->db->get("data");
if ($query->num_rows() > 0)
{
return $query->row_array();
}
else
{
show_error("Database is empty");
}
}
}
?>
And helloworld_view.php:
<html>
<head>
<title><?php echo $page_title ?></title>
</head>
<body>
<?php foreach($result as $row): ?>
<h3><?php echo $row["title"]?></h3>
<p><?php echo $row["text"]?></p>
<br />
<?php endforeach ?>
</body>
</html>
As far as I understand, the Controller constructor is what gets called absolutely first, so I don't think the rest of the files matter at this stage(?).
Upvotes: 4
Views: 6903
Reputation: 392
I had same problem that was resolved by changing 'dbdriver' => 'mysqli'
to 'dbdriver' => 'mysql'
in you config/database.php
. Also make sure your database connection parameters are correct.
Upvotes: 3
Reputation: 82048
My guess, and I would have to see your configs to be sure, is that there is a problem in the initialization of your Loader
. Most commonly this has to do with the automatically loaded libraries, and sometimes it has to do with a bad database configuration. My first suggestion would be to try to get something working using the default configs. If that works, then you have a good starting point.
Upvotes: 1