Welcome Guest, Not a member yet? Register   Sign In
Index function of a controller responds 'selectively' ?!
#1

[eluser]stormbytes[/eluser]
This has got me baffled.

Below is the code from my Asset controller.

Very simple. If the $asset_id arg is not specified (eg. someone manually altered a link or URL/address) then redirect to "Catalog" -

Else..

Load the specified View.

Now here's the funny business:

If I were to manually type base-url.com/asset/ then it would redirect me to 'catalog', as it should - so evidently the index (default) method seems to be working!

But if I type ANY argument following that string (eg. base-url.com/asset/234) it returns 404-page not found!?

I've been hammering my head against this thing for 2 hours now. Either it works, or it doesn't!? What's this 'part-time' working business Smile

Caveat: When I change the name of the function from Index to something else, and call the method in the URL (eg. base-url/asset/foo/234) it works just fine!

Baffling really.. Hoping someone might shed some light on this as I'm pretty much at wit's end.

I know models don't have a 'default' method, but pretty sure classes should respond to 'index'.

Thanks a bunch!

Code:
class Asset extends Controller
{

    function __construct()
    {
        parent::Controller();

        $this->load->model('mod_asset');
    }

    function index($asset_id = FALSE)
    {

        if (!$asset_id) redirect(base_url().'catalog');

        // Page Defaults
        $data['page_title'] = "Details";
        $data['page_desc'] = "BAR!";
        //$data['asset_url'] = $this->mod_asset->get_asset_url($asset_id);
        $data['content'] = 'view_asset';

        $this->load->view('template', $data);
    }

}
#2

[eluser]wiredesignz[/eluser]
The second segment is always the method so you will get 404 with that URL. You need to add routing or use _remap() to intercept the data if you do not wish to display the method name.
Code:
http://domain.tld/asset/index/234

or add the second segment as index
#3

[eluser]Watermark Studios[/eluser]
Dido wiredesignz. To change your URI Routing:

Code:
// system/application/config/routes.php

$route['asset/(:num)'] = "asset/index/$1"
#4

[eluser]stormbytes[/eluser]
Thanks! I think I'm gonna keep it simple and just use a method name.




Theme © iAndrew 2016 - Forum software by © MyBB