CodeIgniter Forums

Full Version: Cannot resolve blank screen following tutorial
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Following the tutorial building a news site, I can't seem to resolve the notorious blank screen. Previously I had resolved a separate blank screen issue by setting the appropriate error reporting values in index.php and php.ini.

I'm running Apache 2.4.18, php 5.6.16, mariadb (mysql) 10.1.9, and phpMyAdmin 4.5.2 locally.

Relevant code segments:

php.ini
Code:
error_reporting = E_ALL
display_errors = On
...
log_errors = On
...

extension=mysqli.so
;extension=mysql.so
;extension=odbc.so
;zend_extension=opcache.so
;extension=openssl.so
extension=pdo_mysql.so


index.php
Code:
define('ENVIRONMENT', 'development');
...


if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
                    ini_set('display_error', TRUE);
...

application/config/config.php
Code:
$config['log_threshold'] = 4;
...

application/config/routes.php
Code:
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

application/controllers/news.php
Code:
<?php

class News extends CI_Controller {

   public function __construct()
   {
       log_message('error', 'News controller __construct()');
       parent::__construct();
       $this->load->model('news_model');
   }

   public function index()
   {
       log_message('error', 'News controller index()');
       $data['news'] = $this->news_model->get_news();
       $data['title'] = 'News archive';

       $this->load->view('templates/header', $data);
       $this->load->view('news/index', $data);
       $this->load->view('templates/footer');
   }

   public function view($slug = NULL)
   {
       log_message('error', 'News controller view($slug = NULL)');
       $data['news_item'] = $this->news_model->get_news($slug);

       if (empty($data['news_item']))
       {
           show_404();
       }
       $data['title'] = $data['news_item']['title'];
       $this->load->view('templates/header', $data);
       $this->load->view('news/view', $data);
       $this->load->view('templates/footer');
   }
}

application/models/news_model.php
Code:
<?php
class News_model extends CI_Model {

   public function __construct()
   {
       log_message('error', 'News_model __construct()');
       log_message('error', '$this->load->database() Line 7');
       $this->load->database();
       log_message('error', 'Load finished Line 9');
   }

   public function get_news($slug = FALSE)
   {
       log_message('error', 'call: get_news()');
       if($slug === FALSE)
       {
               $query = $this->db->get('news');
               return $query->result_array();
       }

       $query = $this->db->get_where('news', array('slug' => $slug));
       return $query->row_array();
   }
}

Please note the log_message() calles in the controller and model. When trying to load localhost/index.php/news, the log output is as follows:

Code:
DEBUG - 2015-12-15 12:44:03 --> Config Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Hooks Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Utf8 Class Initialized
DEBUG - 2015-12-15 12:44:03 --> UTF-8 Support Disabled
DEBUG - 2015-12-15 12:44:03 --> URI Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Router Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Output Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Security Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Input Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Global POST and COOKIE data sanitized
DEBUG - 2015-12-15 12:44:03 --> Language Class Initialized
* ERROR - 2015-12-15 12:44:03 --> News controller __construct()
DEBUG - 2015-12-15 12:44:03 --> Loader Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Controller Class Initialized
DEBUG - 2015-12-15 12:44:03 --> Model Class Initialized
* ERROR - 2015-12-15 12:44:03 --> News_model __construct()
* ERROR - 2015-12-15 12:44:03 --> $this->load->database() Line 7
DEBUG - 2015-12-15 12:44:03 --> Database Driver Class Initialized



So the log_message() call after $this->load->database(); in news_model.php never runs, but I don't have any errors or information to go on.

If you're still with me, I appreciate you reading this far.

Does anyone know of any ways to get more debugging information out of this or any possible fixes? Thanks for any and all input!
(:any) routes have to be the last routes in the routes file,
any route below them will never run.

$route['default_controller'] = 'pages/view'; // this will not work with a sub-folder.
$route['news'] = 'news';
$route['news/(:any)'] = 'news/view/$1';
$route['(:any)'] = 'pages/view/$1';
Thanks for the tip! I've updated routes.php accordingly, but the result and log output remain unchanged.
Your database config might be something wrong.
Good point, I should have included that in the original post.

application/config/database.php (excerpt)
Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'XX';
$db['default']['password'] = 'XXXX';
$db['default']['database'] = 'XXXX';
$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;

I've X'd out the credentials obviously, but I can log in from the command line with:
Code:
mysql -u [USER] -p [dbName]


And then proceed to create/modify tables/records.

Also, in system/database/DB_driver.php there are plenty of calls to log_message() in the event of an error, but I'm not getting any error messages reported about database connectivity problems.
first of all u need to find out point when your script start working wrong

I remeber that I had same problem and it was relate with DB

first of all u can check connection to db with pure php

second, if nothing helps try to start exit('here'); from index.php then in Codeigniter.php and so on.

I remeber that i find out problem in this way where no errors and blank page
@Scion,

Thank you SO much!

* DB connection works with pure php.

* exit(str) is exactly what I was looking for!

Followed execution through DB_driver.php until the db_connect / db_pconnect call. Looking for the declarations of those two functions results in:

Code:
database/drivers/pdo/pdo_driver.php:95:    function db_connect()
database/drivers/sqlite/sqlite_driver.php:59:    function db_connect()
database/drivers/sqlsrv/sqlsrv_driver.php:57:    function db_connect($pooling = false)
database/drivers/postgre/postgre_driver.php:85:    function db_connect()
database/drivers/oci8/oci8_driver.php:79:    public function db_connect()
database/drivers/odbc/odbc_driver.php:65:    function db_connect()
database/drivers/mssql/mssql_driver.php:57:    function db_connect()
database/drivers/cubrid/cubrid_driver.php:61:    function db_connect()
database/drivers/mysql/mysql_driver.php:67:    function db_connect()
database/drivers/mysqli/mysqli_driver.php:69:    function db_connect()

Oh a whim, I uncommented extension=mysql.so in php.ini and everything works!

Can't believe it was such a simple fix. I was under the impression that mysql.so was deprecated.