⚠ 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

add edit view do not work, 404 page not found



Francesco Romeo

Francesco Romeo
  • profile picture
  • Member

Posted 13 October 2016 - 09:18 AM

Hallo!

 

I'm new to groceryCRUD and i am tryng to display a simple table with all functionalities, the implementation is not in the index method as reccomanded in the tutorial.

 

i am using a wamp

 

base url:

$config['base_url'] = 'localhost/main_folder/';

controller:

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


class Welcome extends CI_Controller {

public function index()
{
        $this->load->helper('url');
$this->load->view('home');
}
    public function categorie()
{
        
        $this->load->helper('url');
$this->load->library('grocery_CRUD');
        $crud = new grocery_CRUD();
        $crud->set_table('categorie');
        $crud->set_subject('Categoria');
        $crud->fields('nome','descrizione','note');
        $output = $crud->render();
        
        $this->load->view('categorie',$output);
}
}

the view is very long due the css theme i used so i will include the relevant (i think) parts:

 

     
        <?php foreach($css_files as $file): ?>
            <link type="text/css" rel="stylesheet" href="http://<?php echo $file; ?>" />
        <?php endforeach; ?>
        <?php foreach($js_files as $file): ?>
            <script src="http://<?php echo $file; ?>"></script>
        <?php endforeach; ?>

        <?php echo $output; ?>

when i click on add edit and view i get a 404 error from codeigniter with urls i can see are not good: 

http://localhost/main_folder/index.php/localhost/main_folder/index.php/categorie/add

i tryed to put the base url back to:

$config['base_url'] = '';

but the url comes up very strange:

http://[::1]/main_folder/index.php/categorie/add

i also tryed to put the http:// :

$config['base_url'] = 'http://localhost/pannello_preventivi/';

like this i managed to have a clean url:

http://localhost/main_folder/index.php/categorie/add

but still getting 404 error, can someone help me please? 


Francesco Romeo

Francesco Romeo
  • profile picture
  • Member

Posted 13 October 2016 - 13:38 PM

I discovered that codeigniter requires a route for avery action called so is enaugh to modify the routes.php in the codeigniter config folder and add every route, i did this:

$route['default_controller'] = 'welcome';
$route['categorie'] = 'welcome/categorie';
$route['categorie/add'] = 'welcome/categorie/add';
$route['categorie/insert'] = 'welcome/categorie/insert';
$route['categorie/insert_validation'] = 'welcome/categorie/insert_validation';
$route['categorie/success/:num'] = 'welcome/categorie/success';
$route['categorie/delete/:num'] = 'welcome/categorie/delete';
$route['categorie/edit/:num'] = 'welcome/categorie/edit';
$route['categorie/update_validation/:num'] = 'welcome/categorie/update_validation';
$route['categorie/update/:num'] = 'welcome/categorie/update';
$route['categorie/ajax_list_info'] = 'welcome/categorie/ajax_list_info';
$route['categorie/ajax_list'] = 'welcome/categorie/ajax_list';

and on that page it all works like a charm.

If you want a parametric solution that can work on the same controller:

$route['(:any)/add'] = 'welcome/$1/add';
$route['(:any)/insert'] = 'welcome/$1/insert';
$route['(:any)/insert_validation'] = 'welcome/$1/insert_validation';
$route['(:any)/success/:num'] = 'welcome/$1/success';
$route['(:any)/delete/:num'] = 'welcome/$1/delete';
$route['(:any)/edit/:num'] = 'welcome/$1/edit';
$route['(:any)/update_validation/:num'] = 'welcome/$1/update_validation';
$route['(:any)/update/:num'] = 'welcome/$1/update';
$route['(:any)/ajax_list_info'] = 'welcome/$1/ajax_list_info';
$route['(:any)/ajax_list'] = 'welcome/$1/ajax_list';
$route['(:any)/read/:num'] = 'welcome/$1/read';
$route['(:any)/export'] = 'welcome/$1/export';

Efrain Beltran Orozco

Efrain Beltran Orozco
  • profile picture
  • Member

Posted 13 October 2016 - 23:02 PM

Thanks for the solution, I also create serves tome, but now I must generate a function in mycalled controller add or thus leave it, because I already did it and as my function add this emptyone does not visualize anything to me.

 

so i have a function add but empty so when i click add button it show empty, i need the form to capture the info.

 

sorry for my english.


Francesco Romeo

Francesco Romeo
  • profile picture
  • Member

Posted 14 October 2016 - 18:10 PM

Thanks for the solution, I also create serves tome, but now I must generate a function in mycalled controller add or thus leave it, because I already did it and as my function add this emptyone does not visualize anything to me.

 

so i have a function add but empty so when i click add button it show empty, i need the form to capture the info.

 

sorry for my english.

I don't understand...


JOB

JOB
  • profile picture
  • Member

Posted 23 April 2020 - 08:01 AM

Is there a simpler way of doing the above?

I have the same errors and this solution works well, I feel like if I have to do this for every controller then it shall be cumbersome. Please advice.

Thanks in advance.