0

Using this stackoverflow answer from 2011 on Best Way to Structure Partial Views

I've built up a dashboard base view with sidebars, navigation, and a content area, that should have the content inserted into it on CI _output(), similar to my code example below. When I run $this->load->view('dashboard/base') just by itself I get the dashboard, but after implementing MY_Controller with _output() it shows the data is correct going in, but the dashboard/base view never displays. Instead I get a blank page, empty html markup, with no errors to follow. Just to be clear, if I take the code from MY_Controller _output() and put it in my Dashboard controller, it works fine. So it isn't the view, which works fine with all it's subviews etc.

Okay, no errors lets check php.ini

  1. error_reporting is set to E_ALL
  2. display_error is set to On

Okay, lets check for similarly named classes, and/or views? Scraping everything out there are is only:

  • 1 controller (Dashboard),
  • 1 model (Dashboard_model), and
  • 15 views used to simply construct the dashboard
    • 2 views that have a similar named view (header, and footer), but they are separated by the folder structure, and aren't both being used

... So there are no classes or views clashing

Okay, lets check some stackoverflow question/answer:

  1. make sure MY_Controller is in application/core via source... it sure is
  2. try setting ini_set('display_errors', 1); via source... no errors displayed
  3. try turning on CI loggin and set it to 4 via source no errors in the log

Which logged this:

DEBUG - 2014-08-12 09:04:09 --> Config Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Hooks Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Utf8 Class Initialized
DEBUG - 2014-08-12 09:04:09 --> UTF-8 Support Enabled
DEBUG - 2014-08-12 09:04:09 --> URI Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Router Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Output Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Security Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Input Class Initialized
DEBUG - 2014-08-12 09:04:09 --> XSS Filtering completed
DEBUG - 2014-08-12 09:04:09 --> XSS Filtering completed
DEBUG - 2014-08-12 09:04:09 --> CRSF cookie Set
DEBUG - 2014-08-12 09:04:09 --> Global POST and COOKIE data sanitized
DEBUG - 2014-08-12 09:04:09 --> Language Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Loader Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Controller Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Session Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Helper loaded: string_helper
DEBUG - 2014-08-12 09:04:09 --> Encrypt Class Initialized
DEBUG - 2014-08-12 09:04:09 --> Database Driver Class Initialized
ERROR - 2014-08-12 09:04:09 --> Severity: 8192  --> mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead D:\htdocs\example\app\codeigniter\system\database\drivers\mysql\mysql_driver.php 91
DEBUG - 2014-08-12 09:04:09 --> Session routines successfully run
DEBUG - 2014-08-12 09:04:09 --> Helper loaded: security_helper
DEBUG - 2014-08-12 09:04:09 --> Helper loaded: url_helper
DEBUG - 2014-08-12 09:04:09 --> Helper loaded: utility_helper
DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/content/reporting.php
DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/header.php
DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/sidebar.php
DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/topnav_left.php
DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/topnav_right.php
DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/footer.php
DEBUG - 2014-08-12 09:04:09 --> File loaded: ../codeigniter/application/example/views/dashboard/base.php
DEBUG - 2014-08-12 09:04:09 --> Final output sent to browser
DEBUG - 2014-08-12 09:04:09 --> Total execution time: 0.0512

Okay, so there really is no error... but I still have a blank page? Here's my code example in case it is more useful to someone other than me, now that I feel trodden on and a bit bitter I can't figure this out:

Class Dashboard extends MY_Controller
{
    function __construct() {
        parent::__construct();   
    }

    public function index() {
        $this->load->view('dashboard/content/reports'); // only have "Hello World!" stub in view
    }
}

Class MY_Controller extends CI_Controller
{
    var $page_title = 'my page title';
    var $page_keywords = 'my keywords';
    var $page_description = 'my description';
    var $dashboard_title = 'my dashboard title';

    function __construct() {
        parent::__construct();
        $this->load->model('dashboard_model');
        $this->load->library('session');
        $this->load->helper('security');
        $this->load->helper('url');
        $this->load->helper('utility');
    }

    public function _output($content) {

        $data = array(
            'page_title' => $this->page_title,
            'page_keywords' => $this->page_keywords,
            'page_description' => $this->page_description,
            'dashboard_title' => $this->dashboard_title,
            'content' => &$content
        );

        print_r("<pre>");
        print_r($data);
        print_r("</pre>");

        $this->load->view('dashboard/base', $data);
    } // END public function _output
}

Anyone know what has happened?

As an aside, why is $content passed by reference in the example I referenced for this solution?

Community
  • 1
  • 1
mtpultz
  • 17,267
  • 22
  • 122
  • 201

1 Answers1

0

If you're using _output() in your class it will not echo your data to the screen, you need to do it yourself, and you need the view to return the data for you to echo it, so view needs to use it's third parameter. So in your class the last line of output should be:

echo( $this->load->view('dashboard/base', $data, TRUE) );
mtpultz
  • 17,267
  • 22
  • 122
  • 201