📜 ⬆️ ⬇️

Grocery CRUD, or how I made my life easier for a week

Good afternoon, HabraCommunity!
For almost a month now I have been developing a project on CodeIgniter 2.0 and by the middle of writing I ran into a problem when writing the administrator part. It so happened that I have been acquainted with CI for more than 2 years, and CodeIgniter has not let me down in its abilities yet.
My project itself is estimated at 35 tables and I need to write an admin panel for “hamsters”. Having calculated the approximate man-hours necessary for the development of the interface + software, I was horrified. The enthusiasm subsided a bit (my personal project). Remembering with a kind word at least some CRUD in the old versions, I ventured to “ask Google,” maybe lucky ... And lucky!

I present to your attention - Grocery CRUD | Developer site

Simple and clear generator "CreateReadUpdate Delete" for your tables in CodeIgniter projects

The entire installation boils down to the banal unzipping to the project folder, and creating a controller
')
<?php function _() { $output = $this->grocery_crud->render(); $this->_example_output($output); } ?> 

It leads to the following (developer example):


As you can see, everything you need is already there, but the possibilities do not end there.

Conclusion of the necessary columns in a general view
 <?php function customers_admin() { $this->grocery_crud->set_table('customers'); $this->grocery_crud->columns('customerName','phone','addressLine1','creditLimit'); $output = $this->grocery_crud->render(); $this->_example_output($output); } ?> 

Indicated the table, indicated the columns - and got the beauty:


1: 1 relationship
image
 <?php function employees_admin() { $crud->set_table('employees'); $crud->display_as('officeCode','Office City'); //        Relation $crud->set_relation('officeCode','offices','city'); // set_relation(     , ,     ); $output = $crud->render(); $this->_example_output($output); } ?> 


At the output, we obtain the associated entries:


Relationships through the table
image

If the relative table is large:


If the relative table is small:


AJAX file upload
This is solved in one line:
 ... $crud->set_field_upload('file_url','assets/uploads/files');//   -       ... 

The file gets a 6-character random key prefix when it is loaded.

Additionally:


Total:

He spent no more than an hour on the whole “development” of the admin panel, with viewing the source code. Definitely for all programmers using the CodeIgniter framework - I advise you!

Above the project is actively being developed on GitHub

Source: https://habr.com/ru/post/140744/


All Articles