⚠ 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

Assigning grocery_crud to template (route issue)



jas
  • profile picture
  • Member

Posted 28 June 2012 - 17:51 PM

New to the library. Attempting to implement this functionality which is working however because of my multiple calls to $this->load->view() I believe I have run into a snag.

First I have included this library within my construct like so...

function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->library('grocery_CRUD');
}


At this point my index() function calls each template or view I have setup and assigns them to the default view like so...

public function index()
{
$x = $this->licenses();
$bData = array('message'=>$x->output,
'css_files'=>$x->css_files,
'js_files'=>$x->js_files,
'output'=>$x->output);

$data = array('header'=>$this->load->view('header', '', true),
'footer'=>$this->load->view('footer', '', true),
'main'=>$this->load->view($body, $bData, true),
'login'=>$this->load->view('myTFH/auth', '', true));

$this->load->view('welcome_message', $data);
}
public function licenses()
{
$this->grocery_crud->set_table('license');
return $this->grocery_crud->render();
}


The table data populates the grid without problems however during this load I recieving routing errors like this...
[quote]POST: ajax_list_info - Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.
[/quote]

I realize I may not be implementing this in the same maner as the examples show but is there any way I can tell the current implementation to route through my default controller?

Any help is appreciated.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 28 June 2012 - 18:07 PM

Just move your function the another rather than index and it will work fine. It is a known issue that in some cases grocery CRUD doesn't work with the "index" function so if you just have your functionality in a different function for example:


public function licenses_management()
{
$x = $this->licenses();
$bData = array('message'=>$x->output,
'css_files'=>$x->css_files,
'js_files'=>$x->js_files,
'output'=>$x->output);

$data = array('header'=>$this->load->view('header', '', true),
'footer'=>$this->load->view('footer', '', true),
'main'=>$this->load->view($body, $bData, true),
'login'=>$this->load->view('myTFH/auth', '', true));

$this->load->view('welcome_message', $data);
}
public function licenses()
{
$this->grocery_crud->set_table('license');
return $this->grocery_crud->render();
}


It will work as expected

jas
  • profile picture
  • Member

Posted 28 June 2012 - 18:43 PM

Still recieving the 500 errors when trying to load the ajax_list_info controller. I started looking at the application/libraries/grocery_crud.php source and it seems this is a dynamic route added by your default controller correct?

Would it help to provide any other information>?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 28 June 2012 - 18:55 PM

It depends what error do you receive. If you receive: "The action you have requested is not allowed." this means that you have the scrf_protection set to true , you have to change it to false or else use this work around.

You have to tell me what is the exactly error that you receive and your url path, for example /localhost/test/index.php/examples/my_example

grocery CRUD is clever enough to understand many routes and handle it automatically you don't have to change anything.

jas
  • profile picture
  • Member

Posted 28 June 2012 - 18:59 PM

I already took a look at that error regarding the csrf protection option and have it disabled currently to eliminate this as a possible problem.

The headers are 500 (file missing) errors. Here is the complete example I am attempting to use...


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->library('grocery_CRUD');
}
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->licenses_management();
}
public function licenses_management()
{
/* ensure sessions have been initialized */
session_start();
/* determine if the user has been authenticated */
$body = ((!empty($_COOKIE['token']))||(!empty($_SESSION['token']))) ? 'manage' : 'main';
/* array holder for body elements */
$bData = array();
if ($body === 'manage') {
$x = $this->_licenses();
$bData = array('css_files'=>$x->css_files,
'js_files'=>$x->js_files,
'output'=>$x->output);
}
/* create array of views to load and associate array of elements to populate */
$data = array('header'=>$this->load->view('header', '', true),
'footer'=>$this->load->view('footer', '', true),
'main'=>$this->load->view($body, $bData, true),
'login'=>$this->load->view('myTFH/auth', '', true));
$this->load->view('welcome_message', $data);
}
public function _licenses()
{
$this->grocery_crud->set_table('license');
return $this->grocery_crud->render();
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 28 June 2012 - 19:26 PM

The solution is the same you have to call grocery CRUD function from a different method and not to be at index. Just call the licenses_management and not the index function.

I will be more specific to this, for example don't use[b]: [/b] www.yourproject.com/admin or www.yourproject.com/admin/index
and use another function for example : www.yourproject.com/admin/licenses_management or www.yourproject.com/admin/whatever_you_like.

grocery CRUD actually reads the url and transform everything that you need. It just have a small issue at index methods as codeigniter doesn't give enough information for this.

Try it and it will work for sure.

jas
  • profile picture
  • Member

Posted 29 June 2012 - 17:31 PM

If I call it as http://project/index.php/controller no errors occur, thanks for the help