CodeIgniter Forums
Default index function for controller rendering - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Default index function for controller rendering (/showthread.php?tid=2349)



Default index function for controller rendering - El Forum - 07-31-2007

[eluser]davidk43[/eluser]
Odd this, I've only just started so the problem maybe obvious. I've just started an Account controller:

Code:
class Account extends Controller {

    function Account()
    {
            parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('account');
    }
    
}

which has a matching view:


Code:
<?$this->load->view('template/header');?>

<h1>Your account</h1>

&lt;?$this->load->view('template/footer');?&gt;


If I type the URL:

Code:
http://domain/account/index

this renders correctly with the header/footer views around the index function. However this:

Code:
http://domain/account

will merely render the index function ignoring the partial views, so simply returning:

Code:
<h1>Your account</h1>

help?


Default index function for controller rendering - El Forum - 07-31-2007

[eluser]rustyvz[/eluser]
I believe you need to edit your routes.php in the config directoty and set the following:

Code:
$route['default_controller'] = "index";

But I could be wrong. Still sorta new to all this...


Default index function for controller rendering - El Forum - 07-31-2007

[eluser]davidk43[/eluser]
Hi,

Thanks for that, but that's not quite the problem. It's not routing to the controller that's the problem. Its more about invoking the default function for that controller. so not domain/controller its about the domain/controller/function. It's invoking the index function if not specified in the url, but not rendering the other views.

cheers


Default index function for controller rendering - El Forum - 07-31-2007

[eluser]rustyvz[/eluser]
Ok, my bad... Sorry about that...

Anyway, I took your code and tested it on my machine and it works, as-is, with both urls.

Are you using any URL rewriting or non-vanilla CI libraries/etc?


Default index function for controller rendering - El Forum - 07-31-2007

[eluser]Michael Wales[/eluser]
I agree - any URI re-rerouting or .htaccess goofiness occurring here? An odd issue indeed - one I have yet to experience.


Default index function for controller rendering - El Forum - 07-31-2007

[eluser]davidk43[/eluser]
OK, I ripped out a bunch of function I'd added (I'm attempting to port an existing app into CI) as a custom helper - guess that's not the way to do it, as the moment I stripped it out all worked fine.

Thanks guys, I guess I have some learning ahead of me....