How to install a theme
To install a new theme it is fairly easy. Usually the theme is in a folder structure to just copy it to your project. For example Bootstrap theme has the below folder structure:
assets/ ––– grocery_crud/ ––––––– themes/ ––––––––––– bootstrap-v4/ –––––––––––––––– css –––––––––––––––– fonts –––––––––––––––– images –––––––––––––––– index.html –––––––––––––––– js –––––––––––––––– ...
So you just need to copy the folders into your already existing Codeigniter and Grocery CRUD project. If you don't know how to install grocery CRUD to your project then you can see the installation guide for Grocery CRUD
After you've copied the folder to your project, the bootstrap theme will be installed.
Important notice:️ Be aware that the bootstrap theme is mobile and tablet compatible so you will need to add the below code at the
<head> tag in your template file in order to make it work for mobile and tablet devices:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
If you've already done that, the only remaining thing that you need to do is to set the theme. You can do that by adding the below line at your basic Controller functions
$crud = new GroceryCrud(); $crud->setTheme('bootstrap-v4');
If you are sure that this theme is your favorite one, then you can also add it to your configuration file as a default theme.
More specifically if you go at the file:
app/Config/GroceryCrud.php and change the below line:
public $default_theme = 'flexigrid';
public $default_theme = 'bootstrap-v4';
With that change the final file of
app/Config/GroceryCrud.php will look like this:
With the above change you will not need to add the same extra line at all your functions. Easy-peasy 😃
A full working example can be find below:
$crud->setTable('customers'); $crud->setSubject('Customer', 'Customers'); $crud->columns(['customerName','phone','addressLine1','creditLimit']); $crud->setTheme('bootstrap-v4');
It is that simple! You don't need to configure anything else in order to make it work.