⚠ 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

Integrating GC with existing html framework



Dale
  • profile picture
  • Member

Posted 02 April 2013 - 01:42 AM

A very simple question - hopefully a very simple answer that has eluded me.

 

I'm not sure how to integrate GC with an existing page format of header, navigation and footer. 

I'd like it to appear in my content area of my page. Obviously I also need to ensure the GC css & javascript is included in the page head.

 

Any suggestions/pointers on how to do this?

 

thanks,


davidoster
  • profile picture
  • Member

Posted 02 April 2013 - 08:18 AM

Make different views and load sequentially, like,

 

load->view('header');

load->view('navigation');

load->view('content');

load->view('footer');

 

More information here.


Zalo
  • profile picture
  • Member

Posted 02 April 2013 - 22:55 PM

Another option (and what I am using at the moment) is this:

 

On the html:

 

1) on the header you include this lines:

 

//This loads js setted by gc IF they exists
<?php if (is_array($js_files)) { foreach($js_files as $file): ?>
	<script src="<?php echo $file; ?>"></script>
<?php endforeach; }?>

//This loads css setted by gc IF they exists
<?php if (is_array($css_files)) { foreach($css_files as $file): ?>
	<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; }?>



 

2) And... a simple:

<?php echo $output; ?>

 

Where you want the table/add_form/edit_form to be.

 

 

 

On the controller:

 

1) You save the output of the render function like this: 

$output = $crud->render();

 

Or whatever other variable name you want/like. (Have in mind that render returns an object, not an array)

 

2) You pass that variable ($output in this case) to your view:

$this->load->view('my_template.php', $output, FALSE);

 

 

Hope it helps. Feel free to ask me if you don't quite get something :)

 

Cya


davidoster
  • profile picture
  • Member

Posted 03 April 2013 - 07:26 AM

Another option (and what I am using at the moment) is this:

 

On the html:

 

1) on the header you include this lines:

 

//This loads js setted by gc IF they exists
<?php if (is_array($js_files)) { foreach($js_files as $file): ?>
	<script src="<?php echo $file; ?>"></script>
<?php endforeach; }?>

//This loads css setted by gc IF they exists
<?php if (is_array($css_files)) { foreach($css_files as $file): ?>
	<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; }?>



 

2) And... a simple:

<?php echo $output; ?>

 

Where you want the table/add_form/edit_form to be.

 

 

 

On the controller:

 

1) You save the output of the render function like this: 

$output = $crud->render();

 

Or whatever other variable name you want/like. (Have in mind that render returns an object, not an array)

 

2) You pass that variable ($output in this case) to your view:

$this->load->view('my_template.php', $output, FALSE);

 

 

Hope it helps. Feel free to ask me if you don't quite get something :)

 

Cya

 

 

 

[member=zalo], how this is different from the sample code that is already being distributed with the Grocery CRUD library?

This is what the core developer proposes to us to do!!!


Zalo
  • profile picture
  • Member

Posted 03 April 2013 - 12:23 PM

It is, yes. (with minimal modifications... I am asking if css and js files are set before trying to print them so you won't get a warning, and I call the view right from the function where I configure the gc, instead of from an external one) 

It is also what I am using.

It is ALSO another way of doing what Dale asked to do.

I never said I made a new and never-before seen way to do it so... I don't really see why the complain :p

I just added a little explanation about how it works. Is that wrong?

If the "example" let's him do what he needs to do... what is the big deal?? xD

Is it about the credit? If so:

Oh, Dale... keep in mind that this is basically what the example provided by John Skoumbourdis together with the library does. I quoted it mostly to explain what it does...

 

Happy Coding!

 

 

 

davidoster: there... happy? :)


davidoster
  • profile picture
  • Member

Posted 03 April 2013 - 12:52 PM

Ah, now I get it!

In terms of explanation I have to admit you explain it allright, almost!

Both you and I never pointed out that we are actually using a theme that in order to configure it's view you need to go to the

assets/grocery_crud/themes/your_selected_theme/views and change there the files as needed!

 

I wasn't peaky and I wasn't trying to get credits on behalf of anyone!!!

I was trying to understand if what you posted differs somehow from what is already being included on the examples that come with Grocery CRUD.

At the end of the day, I am a developer also and I don't represent anyone, except myself!!!  ;)

 

Anyway thanks for helping out all of us, keep doing it!


Zalo
  • profile picture
  • Member

Posted 03 April 2013 - 13:19 PM

True, good point!

 
GC has it's own themes... they are found where davidoster said.
I wouldn't advise trying to change anything else than the css if you are just a begginer in GC, but if you have the time and you really need/want to, go ahead (and then share it with the comunity! :D)
 
You can (and I would advice) add your own css files to your html template AFTER those of GC so you can update the library without loosing your styles.
 
By the way, what html framework are we talking about? Maybe we could be more specific if we knew that... (for example, if you are talking about twitter bootstrap, the git version -beta of 1.4- has already a bootstrap theme, so you don't actually need to do anything to integrate it :p)

davidoster
  • profile picture
  • Member

Posted 03 April 2013 - 14:31 PM

And datatables theme is using the jQuery UI's themeroller!


Dale
  • profile picture
  • Member

Posted 04 April 2013 - 05:12 AM

Make different views and load sequentially, like,

 

load->view('header');

load->view('navigation');

load->view('content');

load->view('footer');

 

More information here.

 

--------

This is one way of doing it, but you end up with the question of where you put the </body></html> etc. You can dump it in the footer, but where do you put the <body> as well?

My current structure has all of that structure in a single file (body.php) which does php includes for navigation, content and footer which I specify via the parameter to $this->load->view. 

 

If you load up the views separately you need to slot in all of the opening/closing tags in the controller, rather than just having them in the view where they should be...


davidoster
  • profile picture
  • Member

Posted 04 April 2013 - 09:54 AM

[member=dale] Try to pass $data to the view and on the view put <?php ?> tags to check upon viewing what to show.

Usually this is the way I do it.

You don't actually move the logic to the view. You just check upon current status what needs to be displayed.

It's pretty clean actually like this.


Dale
  • profile picture
  • Member

Posted 04 April 2013 - 11:55 AM

Hi David,

 

I've been trying to do that, but when you pass through the GC render you can't pass in any other objects. :-(


Dale
  • profile picture
  • Member

Posted 04 April 2013 - 13:13 PM

Hi guys, finally fixed it. 

 

I simply converted the GC render from an object to an array, and then added the components to the data array I was passing in to the load->view method.

 

Thanks for your help!


Zalo
  • profile picture
  • Member

Posted 04 April 2013 - 17:02 PM

Which version of CI are you using?

I always send the output of render() right to the view and never had any trouble.