• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I create a nested view within a nested view?

#16
@PaulD Did a lot of reading yesterday. Can't understand why something as conceptually as simple as a template for a view can be so obscure in the CI context. Anyway, this AM I tried to just copy/past code from your posts, adapted to my environment. My home controller looks like this now:


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
C_home extends CI_Controller {
    public function __construct()   {
        parent::__construct();
        $this->load->model('M_tunes');
        $this->load->model('M_filters');
        $this->load->model('M_links');
        $this->load->helper('url');
    }
    public function index() {
        // basic layout data - just example of setting some data
        $this->template_library->set_page_data('meta_title''mz_Library');
        $this->template_library->set_page_data('page_title''MZ Library');
        // dynamic data collection
        $this->template_library->set_page_data('template'$this->load->view('partials/topper_ssv'));
        // render view
        $this->template_library->render_page('home_view');
    }

I've tried several variations of method names / capitalization, etc. but keep getting errro on 1st line in index():

PHP Code:
$this->template_library->set_page_data('page_title''MZ Library'); 

Error Message: "Undefined property: C_home::$template_library"

The template_library file in aopplication/libraries is:
PHP Code:
<?php if ( !defined('BASEPATH')) {exit('No direct script access allowed');} 

class 
Template_library {
    public $page_data = array();

    public function __construct()   {
        $this->CI =& get_instance();
    }
    // setter to add data to page_data from controller
    public function set_page_data($name$data NULL) {
        $this->page_data[$name] = $data;
        return;
    }
    // render a page view
    public function render_page($template)    {
    // render a page - this can be as complex as you like of course, here I just output some views.
        $this->CI->load->view('common/header_v'$this->page_data);
        $this->CI->load->view($template);
        $this->CI->load->view('common/footer_v');
    }


Any suggestions?
Reply


Messages In This Thread
RE: How do I create a nested view within a nested view? - by codeguy - 09-30-2017, 10:30 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.