• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Default index function for controller rendering

Odd this, I've only just started so the problem maybe obvious. I've just started an Account controller:

class Account extends Controller {

    function Account()
    function index()

which has a matching view:


<h1>Your account</h1>


If I type the URL:


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


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

<h1>Your account</h1>


I believe you need to edit your routes.php in the config directoty and set the following:

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

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


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.


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?

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

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.