Grocery Crud Fields in Regular PHP Views?
- Single Page
Posted 21 December 2011 - 13:33 PM
I like everything I'm learning about Grocery CRUD. I definitely see how it makes is easy to set up forms and do the crucial CRUD operations.
But all the examples on this site show tables of information. Are there any examples of how Grocery Crud fields can be displayed in the layouts I make in views PHP files?
For example, in a real estate site, I would need to have tables for the admin to edit entries. But I also would need to grab specific fields to create a layout for listings pages shown to regular site visitors.
I'm guessing this is not a problem in Grocery CRUD. But since I'm still new at CodeIgniter and Grocery CRUD, it would be great to see an example or two.
Thanks,
Matthew
Posted 21 December 2011 - 20:52 PM
Greetings,
I like everything I'm learning about Grocery CRUD. I definitely see how it makes is easy to set up forms and do the crucial CRUD operations.
But all the examples on this site show tables of information. Are there any examples of how Grocery Crud fields can be displayed in the layouts I make in views PHP files?
For example, in a real estate site, I would need to have tables for the admin to edit entries. But I also would need to grab specific fields to create a layout for listings pages shown to regular site visitors.
I'm guessing this is not a problem in Grocery CRUD. But since I'm still new at CodeIgniter and Grocery CRUD, it would be great to see an example or two.
Thanks,
Matthew
[/quote]
Actually grocery CRUD is created only to have a grid and forms for the crud operation. To have your data at the front-end of the website is something you have to do it manually . A good start is to you use models and the active record of codeigniter ( http://codeigniter.c...ive_record.html ) . Grocery CRUD retrieves data only for the crud and the crud operations, it don't create models. Even if we create some functions to get the data, it's way more easier and simple to take data from the active record. Let's have an example:
For the example of the simple set_relation - http://www.grocerycr.../set_a_relation
Your query will simply will be to your front-end model:
$this->db->select('employees.*, offices.city as city');
$this->db->join('offices','offices.officeCode = employees.officeCode','left');
$this->db->get('employees')->results();
So it is just three lines of code to retrieve all the data of employees. You can also add where clauses or whatever you like to your front-end website without any problem. If you like you can have grocery CRUD to your front-end controller with the function unset_operations. So in the same example you will simply have the below code to have just the grid without add/edit/delete functionality :
....
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('employees');
$crud->display_as('officeCode','Office City');
$crud->set_subject('Employee');
$crud->unset_operations();
$crud->set_relation('officeCode','offices','city');
$output = $crud->render();
$this->_example_output($output);
....
Posted 22 December 2011 - 02:22 AM
Thanks for the explanation. To be clear, I should have said that I do not expect Grocery Crud itself to do this.
I just want to make sure the data produced by Grocery Crud is available for use in CodeIgniter views and controllers. Is it accurate to say that Grocery Crud is the engine of collecting information, but the information it collects is available beyond Grocery Crud?
I'm still new at CodeIgniter and Grocery Crud, so I apologize for my simple questions. But maybe this could be a good subject for a tutorial: how to use Grocery Crud data in CodeIgniter views and controllers?
Thanks,
Matthew
EDIT: I think I have a better way to explain this! Let's say I'm creating a real-estate listing site. Of course, I see how to use Grocery Crud to gather all the listings data (address, owner name, price, etc) and administer that data with Grocery Crud tables. But I'd also like to re-use all those field submissions to create property listings layouts (views) to show site visitors.
Posted 06 August 2013 - 18:59 PM
I haven't found an existing one. You may need to modify source code called by "render()" function in Grocery_CRUD.php
Posted 07 August 2013 - 04:55 AM
I haven't found an existing one. You may need to modify source code called by "render()" function in Grocery_CRUD.php
Hello and welcome to the forums [member=magnum].
This is a very old question.
As the core developer said this is not supported. Whoever needs to get part of the data just needs to use the Active Record of CodeIgniter and bind the display of the results to a custom view.
There is no need, and also not at all advisable, to modify the source code of the library, especially for such a simple thing to do.