I created the controller in codeigniter but when I load the page I keep getting a 403 error and nothing from the database will populate. I have attached a picture.
⚠ 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. ⚠
Posted 03 March 2020 - 23:17 PM
I created the controller in codeigniter but when I load the page I keep getting a 403 error and nothing from the database will populate. I have attached a picture.
Posted 03 March 2020 - 23:25 PM
My Controller Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // Add those two lines at the beginning of your controller include(APPPATH . 'libraries/GroceryCrudEnterprise/autoload.php'); use GroceryCrud\Core\GroceryCrud; class User extends BackendController { private function _getDbData() { $db = []; include(APPPATH . 'config/database.php'); return [ 'adapter' => [ 'driver' => 'mysqli', 'host' => $db['default']['hostname'], 'database' => $db['default']['database'], 'username' => $db['default']['username'], 'password' => $db['default']['password'], 'charset' => 'utf8' ] ]; } private function _getGroceryCrudEnterprise($bootstrap = true, $jquery = true) { $db = $this->_getDbData(); $config = include(APPPATH . 'config/gcrud-enterprise.php'); $groceryCrud = new GroceryCrud($config, $db); return $groceryCrud; } public function index() { $crud = $this->_getGroceryCrudEnterprise(); $crud->setTable('users'); $crud->setSubject('User', 'Users'); $crud->columns(['first_name','last_name','email','phone', 'active', 'groups']); $crud->setRelationNtoN('groups', 'user_groups', 'groups', 'user_id', 'group_id', 'name'); $output = $crud->render(); $this->_example_output($output); } function _example_output($output = null) { if (isset($output->isJSONResponse) && $output->isJSONResponse) { header('Content-Type: application/json; charset=utf-8'); echo $output->output; exit; } $this->load->view('gcrud/example.php',$output); } }
My View code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <?php foreach($css_files as $file): ?> <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" /> <?php endforeach; ?> </head> <body> <div style="padding: 20px 10px;"> <?php echo $output; ?> </div> <?php foreach($js_files as $file): ?> <script src="<?php echo $file; ?>"></script> <?php endforeach; ?> </body> </html>
Posted 04 March 2020 - 06:19 AM
Hi kevbo75217,
Try inputting the actual values of the host, database, username, password first just to test if it works.
I hope this helps... :)
Posted 04 March 2020 - 09:15 AM
Thank you for responding larasmith,
The error wasn't related to Grocery Crud. It was from a template library that I installed ci-simplicity. They were both using the same variable for the output buffer. I had to remove it in order to get grocery crud to work. Love the library though.