CodeIgniter Forums
having problem creating a default controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: having problem creating a default controller (/thread-31293.html)



having problem creating a default controller - El Forum - 06-13-2010

[eluser]UdayD[/eluser]
Hi!
m just using CI for developing one project. I have just created one controller named main and have been calling it a default controller by changing the value of default controller from welcome to main(name of my controller) but when i hit a url
http://locahost/mysite/index.php it gives 404 error but when again i put the default controller as welcome it shows the page. I have created the controller 'main' inside the applications folder inside the system folder.
Please let me know what is the problem.
thanks in advance !


having problem creating a default controller - El Forum - 06-14-2010

[eluser]cahva[/eluser]
So you main controller is in here for sure?:
system/application/controllers/main.php

Post your main controller code.


having problem creating a default controller - El Forum - 06-14-2010

[eluser]Ivar89[/eluser]
Default controller is defined in map config->routes.php
If your default controller is main it should look like thisSadroutes.php)
Code:
$route['default_controller'] = "main";
controller:
Code:
class main extends Controller
{
    function main()
    {
         parent::controller();
    }
        function index()
{
$this->load->view('main/index');
}



having problem creating a default controller - El Forum - 06-14-2010

[eluser]UdayD[/eluser]
i have written my controller like
Code:
class main extends Controller
{
    function main()
    {
         parent::controller();
    }

function page()
{
$this->load->view('main/index');
}

do i need that name of function as index can i change it to name page.
or from where i need to change the function name from where the index function is called so that i can change to name " page" function


having problem creating a default controller - El Forum - 06-14-2010

[eluser]Ivar89[/eluser]
you can change it to something else yes, but index is loaded automaticly so if you change it to page your URL will be:

http://locahost/mysite/index.php/page

and BTW Thats the way I do it
Code:
$this->load->view('main/index');
\\main/index is the mapped view->main->index.php, if you do not have multiple map in your view map it should simply say: ('index');



having problem creating a default controller - El Forum - 06-14-2010

[eluser]UdayD[/eluser]
sorry for the earlier mistake i've made.
my code is as below
Code:
class main extends Controller
{
    function main()
    {
         parent::controller();
    }

function page()
{
$this->load->view('main');
}
}
here i have a view as main.php and a controller as main.php in the controller i have a function page which i have to call when my default controller loads.
So my question is do i need to write an index funtion instead of page function. or how will my page functions get called when my user access following url
Code:
http://server.com/index.php
this url must call my page function which will load my main view.


having problem creating a default controller - El Forum - 06-14-2010

[eluser]Ivar89[/eluser]
I guess you could make your default_controller
Code:
$route['default_controller'] = "main/page";
and it should work.


having problem creating a default controller - El Forum - 06-17-2010

[eluser]UdayD[/eluser]
thanks its done in that way u showed