⚠ 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

Route problem



jgalak
  • profile picture
  • Member

Posted 24 February 2013 - 02:04 AM

I seem to be running into a routing problem.  I have my codeigniter/Grocery CRUD project living at "www.jgalak.com/heraldry/rolls/"  The config file has the line:

 

$config['base_url']    = 'http://www.jgalak.com/heraldry/rolls/'; 

The main controller is in the file roll_c.php, in the rolls() function, and the routes.php file has just one line:

$route['default_controller'] = "roll_c/rolls";


But when I click on "Edit" or "Add", I get a 404 error.  Not sure if this could be related to the JavaScript problem I posted above (/topic/1410-pages-of-rows-on-the-grid-view/)

 

I suspect I screwed something up with the autorouting, advice appreciated.

 

Thanks,

Juliean.


victor
  • profile picture
  • Member

Posted 24 February 2013 - 08:27 AM

is your problem solved?

davidoster
  • profile picture
  • Member

Posted 24 February 2013 - 09:42 AM

First of all, you don't need to put the the 'base_url' at all! Codeigniter is clever enough to get it itself.

But your line $route['default_controller'] = "roll_c/rolls"; is wrong!!!!

The config setting $route['default_controller'] must have the name of the class that you want CodeIgniter to load at start.

From the looks of it I don't think you have a controller class called roll_c/rolls????

So your problem is indeed not a javascript one!!!

If your controller's class name is called roll_c then this line should be like this: $route['default_controller'] = "roll_c";


jgalak
  • profile picture
  • Member

Posted 24 February 2013 - 17:40 PM

 

 
If your controller's class name is called roll_c then this line should be like this: $route['default_controller'] = "roll_c";

 

 

 

Forgive the basic questions, I'm very new to PHP/CI/GC...

 

Doing the above calls the index() function.  All of the functionality lives in the rolls() function, as my understanding is that the grocery crud code should not be in an index() function, right? 

 

I made the above change, and put the single line "$this->rolls();" in the index() function.  There is no difference in behavoir - the grid still comes up, the "add"and "edit" buttons still cause 404 error, and the javascript is still not working right (can't advance pages).

 

Any advice appreciated,

Thanks,

Juliean.

 

Thanks,

Juliean.


davidoster
  • profile picture
  • Member

Posted 24 February 2013 - 23:59 PM

Then there is a hosting problem!

Could be a PHP problem.

Check the error logs of your hostgator account under this domain.


jgalak
  • profile picture
  • Member

Posted 25 February 2013 - 17:26 PM

That's possible, but when I built the example in the tutorial, everything (javascript and the add/edit buttons) work fine.  See here: http://www.jgalak.com/test2/index.php/main/employees

 

The only difference I've been able to find is that I disn't try to do routing - I called the function directly (/main/employees to get to the function employees on the controller class main)

 

In fact, if I call my function directly in the troubled application (http://www.jgalak.com/heraldry/rolls/index.php/roll_c/rolls/) rather than through auto routing (http://www.jgalak.com/heraldry/rolls/)  everything works fine as well.

 

So it really seems like a routing problem of some sort...

 

I suppose I can just set up some auto-redirects, but that seems a clumsy way to do it...

 

Thanks,

Juliean.


victor
  • profile picture
  • Member

Posted 25 February 2013 - 21:37 PM

GC uses segments of controller and function. you can use GC with full path to function.

victor
  • profile picture
  • Member

Posted 25 February 2013 - 21:41 PM

sho the routing file and code of the controller.

jgalak
  • profile picture
  • Member

Posted 25 February 2013 - 22:21 PM

controller (application/controllers/roll_c.php):

 

<?php if (! defined('BASEPATH')) exit('No direct script access allowed');

class roll_c extends CI_Controller 
{
	function __construct()
	{
		parent::__construct();
		
		$this->load->database();
		$this->load->helper('url');
		$this->load->library('grocery_CRUD');	
		$this->load->library('session');
	}
	public function index()
	{
		$this->rolls();
	}
	
	public function rolls()
	{
		$crud = new grocery_CRUD();
	
		if($this->session->userdata('logged_in'))  //if not logged in, disable editing
		{
			$session_data = $this->session->userdata('logged_in');
			$data['username'] = $session_data['username'];
		}
		else
		{
			$crud->unset_delete();
			$crud->unset_edit();
			$crud->unset_add();
			$data['username'] = '';
			//TODO:add detailed view
		}
			
		
		$crud->columns('Roll_Name','Link','Description', 'ArtworkStyleID', 'DateStart', 'DateEnd', 'Country');
		$crud->fields('Roll_Name','Link','Description', 'ArtworkStyleID', 'DateStart', 'DateEnd', 'Country');
		
		//validation rules
		$crud->required_fields('Roll_Name','Link');
		$crud->set_rules('DateStart', 'Earliest Date', 'integer');
		$crud->set_rules('DateEnd', 'Latest Date', 'integer');
		
		//foreign key settings
		$crud->set_relation('ArtworkStyleID', 'ArtworkStyles', 'Artwork_Style_Name');
		$crud->set_relation('Country', 'Countries', 'Country_Name');
		
		//column and field labels
		$crud->display_as('Roll_Name', 'Roll of Arms Name');
		$crud->display_as('ArtworkStyleID', 'Artwork Style');
		$crud->display_as('DateStart', 'Earliest Date');
		$crud->display_as('DateEnd', 'Latest Date');
		
		//display links correctly
		$crud->callback_column('Link', array($this,'callback_webpage_handler'));
	
		$crud->set_subject('Roll of Arms');
		$crud->set_table('Rolls');
		
		//set paging options
		$this->config->load('grocery_crud');
		$this->config->set_item('grocery_crud_default_per_page', '1000');
		$crud->set_paging_options(array('10','25','50','100','1000'));
		
		//set sorting.  TODO: Sort options
		$crud->order_by('Roll_Name');
		
		$output= $crud->render($data['username']);
		
		$this->load->view('listview.php',$output);
	}
	

	 function logout()
	 {
	   $this->session->unset_userdata('logged_in');
	   $this->session->sess_destroy();
	   redirect('roll_c/rolls', 'refresh');
	 }
	 
	 function callback_webpage_handler($value, $row)
	 {
		$url = $row->Link;
		
		if ($url[0] == '#') //trim leading and trailing '#' signs.
		{
			$url = substr($url, 1, (strlen($url)-2));
		}
		
		return "<a href='".$url."'>Link</a>";
	 }

	
}
?>

jgalak
  • profile picture
  • Member

Posted 25 February 2013 - 22:21 PM

routes file (application/config/routes.php):

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
|	example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
|	http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There area two reserved routes:
|
|	$route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
|	$route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router what URI segments to use if those provided
| in the URL cannot be matched to a valid route.
|
*/

$route['default_controller'] = "roll_c";



/* End of file routes.php */
/* Location: ./application/config/routes.php */

victor
  • profile picture
  • Member

Posted 25 February 2013 - 22:27 PM

you can't use GC in the default controller and 'index' function without full path to function in the url. From docomentation: Important Note: Please make sure that you don't have grocery CRUD to the index function of your controller as it is a known issue that it will not work on index. Just move it to another method. For example "employees" or something else except index.

jgalak
  • profile picture
  • Member

Posted 25 February 2013 - 23:21 PM

Ah!  Ok, I thought I just couldn't use the function "index()" for it.  I will have to set up a redirect then, that's likely the easiest solution.  Thanks, I will give it a try and report back if I continue to have problems.


jgalak
  • profile picture
  • Member

Posted 27 February 2013 - 18:08 PM

Ok, so calling the functions directly works, but now there's a different problem - I can't seem to add.  When I click add, I get the add window.  When I click "save" or  "save and go back to list", I get the "Loading, Saving data" message, but nothing happens.  No record gets added, and the "save and go back to list" button doesn't take me back to the list.

 

For reference, the edit functionality works perfectly.

 

Any thoughts?

 

Thanks,

Juliean.


davidoster
  • profile picture
  • Member

Posted 03 March 2013 - 10:09 AM

Can't come up with any!!! Very strange.