Welcome Guest, Not a member yet? Register   Sign In
page not found
#1

[eluser]nuge[/eluser]
Hi-
I'm a newbie... as you'll see with my question.... and my code.

The problem I have is that one page is displayed as expected. I then click on a link on that generated page and I come up with the "404 Page not found" error.

I have the following in autoload.php:
$autoload['helper'] = array('url', 'form');

This is invList class (held in the system/application/controllers folder)
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class InvList extends Controller {

    public function _construct()
    {
        parent::Controller();
    }
    
    function index()
    {
        $this->load->model( 'invModel' );
        $data['xtype'] ='';
        $data['base_url'] = $this->config->item('base_url') . "index.php/";
        $data['query'] = $this->invModel->getInventory();
        $this->load->view('invListView', $data);
    }
}

?>
Then in invListView.php (stored in system/application/views) I have the following:
Code:
<html>
<head>
</head>
<body>
  <h1>Opportunity Inventory</h1>
  <br />
  <h2>Inventory - List</h2>
  &lt;?php
  foreach( $query->result() as $row ):

      $sku = $row->sku;
      echo "<br /><a href='".$base_url."invEdit/$sku'>$sku</a>";

  endforeach;
  ?&gt;
&lt;/body&gt;
&lt;/html&gt;

Everything appears to be working until I click on one of the links generated by invListView. The result is "404 Page Not Found".

invEdit.php (stored in system/application/controllers folder):
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class InvEdit extends Controller {

    public function _construct()
    {
        parent::Controller();
    }
    
    function index( $sku )
    {
            echo "hello";
            exit;
        $this->load->model('invModel');
        $data['query'] = $this->invModel->getInventoryWhere( $sku );
        $this->load->view('invEditView', $data);
    }
}

?&gt;

As you can see, I've added echo and exit statements here in the invEdit class. I want to ensure that CI sees and executes this before trying to call invEditView.

something is getting lost along the way (including myself!) so any and all suggestions are greatly appreciated! I've tried this code in several different ways and have tried to cut it back to this bare minimum to make sure I'm not doing anything else to keep it from functioning. I just don't understand how it could execute the first class and then lose track of the second controller.

Please let me know if any further info is needed.

Thanks in advance!
nuge
#2

[eluser]nuge[/eluser]
..
#3

[eluser]Aken[/eluser]
CI's default URL scheme goes like this: example.com/index.php/class/function/ID

Basically you're telling CI to call a function that doesn't exist.

I'd go into your Routes config file, and set a route for that URL to go back to your InvEdit class' default function.

Code:
$route['invedit/:num'] = "invedit";

And then use the URI Segment function to pull the SKU you'd like to edit.

Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class InvEdit extends Controller {

    public function _construct()
    {
        parent::Controller();
    }
    
    function index()
    {
        $sku = $this->uri->segment(2);
        
        $this->load->model('invModel');
        $data['query'] = $this->invModel->getInventoryWhere($sku);
        $this->load->view('invEditView', $data);
    }
}

?&gt;
#4

[eluser]nuge[/eluser]
Thanks so much for your help, Aken!

Not only have you educated me on the config/routes.php file but, more importantly, you've pointed out the obvious and I have since re-written my invList class -- as inventory.php -- which properly holds both the list_sku, edit_sku and other functions.

Again, thanks for all your help!
#5

[eluser]Aken[/eluser]
You're very welcome. Happy coding!




Theme © iAndrew 2016 - Forum software by © MyBB