Welcome Guest, Not a member yet? Register   Sign In
Default index function for controller rendering
#1

[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?
#2

[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...
#3

[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
#4

[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?
#5

[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.
#6

[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....




Theme © iAndrew 2016 - Forum software by © MyBB