⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Using Custom Template



h4kl0rd
  • profile picture
  • Member

Posted 05 October 2013 - 10:19 AM

I'm using the latest Grocery CRUD (version 1.4.1).

I want to integrate a custom template and I have configured my files as follows:

 

I created an includes directory in views, which contains the following files:

  • header.php - contains header files like js,css...
  • footer.php - contains footer files
  • template.php - loads header, content and footer

My template.php looks like this:

<?php
$this->load->view('includes/header');
$this->load->view($content);
$this->load->view('includes/footer');

This is how I call them from the controller:

public function index()
{
     $data['content'] = 'index';
     $this->load->view('includes/template', $data);
}

After using Grocery CRUD, my controller looks like this:

class Users extends CI_Controller {

    public function __construct() 
    {
        parent::__construct();

        $this->load->library('grocery_CRUD');
    }

    public function output($output = null)
    {
        $this->load->view('output_view',$output);
    }

    public function index()
    {
        $this->output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
    }

    public function view()
    {
        try {
            $crud = new grocery_CRUD();

            $crud->set_theme('twitter-bootstrap');
            $crud->set_table('users');

            $crud->...

            $output = $crud->render();
            $this->output($output);            

        } catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
}

I went through one of the threads (Template controller to grocery CRUD). It didn't seem to work.

How do I integrate my custom template with Grocery CRUD?

 

 


h4kl0rd
  • profile picture
  • Member

Posted 10 October 2013 - 09:19 AM

At last I succeeded in integrating my custom template with Grocery Crud.

 

Here's my implementation:

 

I created a universal view that works for all my output: views >> out.php

In the head of my file, I added the grocery_crud styles and scripts:

<?php 
    foreach($css_files as $file): ?>
      <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
    <?php endforeach; ?>
    <?php foreach($js_files as $file): ?>
      <script src="<?php echo $file; ?>"></script>
    <?php endforeach; ?>

 

In my Controller, I made the following modifications:

try {
      $crud = new grocery_CRUD();

      $crud->set_theme(...);
      $crud->set_table(...);

      $crud->....

      $output = $crud->render();

      // comment or remove the default grocery_crud output
      //$this->output($output);

      // load your custom view
      $this->load->view('out', $output);
            
 } catch(Exception $e){
      show_error($e->getMessage().' --- '.$e->getTraceAsString());
 }

IDe
  • profile picture
  • Member

Posted 17 April 2015 - 13:49 PM

 

At last I succeeded in integrating my custom template with Grocery Crud.

 

Here's my implementation:

 

I created a universal view that works for all my output: views >> out.php

In the head of my file, I added the grocery_crud styles and scripts:

<?php 
    foreach($css_files as $file): ?>
      <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
    <?php endforeach; ?>
    <?php foreach($js_files as $file): ?>
      <script src="<?php echo $file; ?>"></script>
    <?php endforeach; ?>

 

In my Controller, I made the following modifications:

try {
      $crud = new grocery_CRUD();

      $crud->set_theme(...);
      $crud->set_table(...);

      $crud->....

      $output = $crud->render();

      // comment or remove the default grocery_crud output
      //$this->output($output);

      // load your custom view
      $this->load->view('out', $output);
            
 } catch(Exception $e){
      show_error($e->getMessage().' --- '.$e->getTraceAsString());

I tried this implementation ,, no way ,, I cant load my template with GC