Welcome Guest, Not a member yet? Register   Sign In
having problem creating a default controller
#1

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

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

Post your main controller code.
#3

[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');
}
#4

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

[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');
#6

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB