My view appears twice |
[eluser]xwero[/eluser]
i just did a quick test with following file structure - controllers -- index.php -- home --- index.php The index.php has this code Code: <?php Then i added in the controllers directory the home.php file and i got routed to that controller so files are higher class than directories. Plume what is in your routes.php file?
[eluser]Plume[/eluser]
Not sure to understand everything cause bad english. Have I to route every controller located in sub folder ? What's your content of home.php ? I tested : Code: <?php Quote:heyhey When I test : Code: <?php Code: bouhbouh And when I test another url like home/test : Code: <?php Quote:Hey I'm lost :/ Layout.php : Code: <?php layout.php ( main layout ) : Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
[eluser]xwero[/eluser]
The home.php content was Code: <?php You dont have to route every controller but i was trying to mimic the scenario you describe here and my output was the one i expected to see. So i asked myself why do you get the output twice and that is why i asked for the content of your routes.php file. Maybe that is the cause of your problem.
[eluser]Plume[/eluser]
Just having this : Code: $route['default_controller'] = "index"; Don't think there is a problem but ... ^^
[eluser]Plume[/eluser]
Ok, I changed my test.php file : Code: <?php I'm now trying to find why Index controller doesn't work and just this one :/
[eluser]Dready[/eluser]
As wiredesignz was telling you, you have double output because the "index" method is called twice : once when the object is created, and once when code igniter, through the routing process, call the default method. To be a little more explicit : Code: class testme { This code will echo "hi there !"; And now if you try : Code: class testme { When you have a controller with "index" as the class name , and you hit the URL http://youserver/index.php/index , codeigniter first create an object of your controller ( new Index() ) and because the default method called by codeigniter is "index", and because in your URL you didn't specify another method, codeigniter then call your "index" method once again. Now if you create another method inside your controller, for example : Code: class Index extends controller { and then you hit the URL http://youserver/index.php/index/foo it will echo "in index in foo ". To resume if I were you I wouldn't make a controller having "index" a the class name. Good luck.
[eluser]Plume[/eluser]
Ok, I understand. Sorry :/ But, if I can't create a controller named Index, how can I affect a default controller when my routing file specify index has default ? Just change default will be OK ? Have I to be careful every time to have no method named like my Controller ? Is that it or I'm always wrong ?
[eluser]Dready[/eluser]
[quote author="Plume" date="1222804240"]Ok, I understand. Sorry :/ But, if I can't create a controller named Index, how can I affect a default controller when my routing file specify index has default ? Just change default will be OK ? Have I to be careful every time to have no method named like my Controller ? Is that it or I'm always wrong ?[/quote] Yes just change the default. Yes be careful every time to have no method named like your Controller. :-) You got it Plume... and welcome to CI !
[eluser]Plume[/eluser]
Yeehaaa ! So thanks boys ! I now can continue further ! See ya soon for next problem :d @tchaOo° |
Welcome Guest, Not a member yet? Register Sign In |