0

I am trying to reuse a table template for the table library in multiple pages. I have tried to save the template in a *php file to later call it as an include but that isn't working. My code looks like this:

//on the controller
$this->load->view('includes/tabularDataTemplate.php');

//this is the contents of the tabularDataTemplate.php file    
$tmpl = array (
    'table_open'          => '<table border="1" cellpadding="4" cellspacing="0">',

    'heading_row_start'   => '<tr>',
    'heading_row_end'     => '</tr>',
    'heading_cell_start'  => '<th>',
    'heading_cell_end'    => '</th>',

    'row_start'           => '<tr>',
    'row_end'             => '</tr>',
    'cell_start'          => '<td>',
    'cell_end'            => '</td>',

    'row_alt_start'       => '<tr>',
    'row_alt_end'         => '</tr>',
    'cell_alt_start'      => '<td>',
    'cell_alt_end'        => '</td>',

    'table_close'         => '</table>'
    );

$this->table->set_template($tmpl);

I am sure there has to be a better (working) way to achieve this.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

I haven't tried it out, but you can do something like this:

//on the controller
$tmpl = $this->load->view('includes/tabularDataTemplate.php','',TRUE);
  //This will return view file as string.

//this is the contents of the tabularDataTemplate.php file    
array (
    'table_open'          => '<table border="1" cellpadding="4" cellspacing="0">',

    'heading_row_start'   => '<tr>',
    'heading_row_end'     => '</tr>',
    'heading_cell_start'  => '<th>',
    'heading_cell_end'    => '</th>',

    'row_start'           => '<tr>',
    'row_end'             => '</tr>',
    'cell_start'          => '<td>',
    'cell_end'            => '</td>',

    'row_alt_start'       => '<tr>',
    'row_alt_end'         => '</tr>',
    'cell_alt_start'      => '<td>',
    'cell_alt_end'        => '</td>',

    'table_close'         => '</table>'
    );

$this->table->set_template($tmpl);
Kalpesh Patel
  • 2,772
  • 2
  • 25
  • 52
  • Thanks, but I get an error "Unable to load the requested file: includes/tabularDataTemplate.php" – user1765388 Nov 06 '12 at 11:45
  • Have you checked the file path? – Kalpesh Patel Nov 06 '12 at 12:22
  • Yes, the file path seems fine. – user1765388 Nov 07 '12 at 00:30
  • Follow this links which may helps you: http://stackoverflow.com/questions/10648752/codeigniter-unable-to-load-the-requested-file, http://stackoverflow.com/questions/8021984/unable-to-load-the-requested-file, http://stackoverflow.com/questions/6665012/unable-to-load-the-requested-file-codeigniter, http://codeigniter.com/forums/viewthread/95880/#485625 – Kalpesh Patel Nov 07 '12 at 04:12