Welcome Guest, Not a member yet? Register   Sign In
default_controller question.
#1

[eluser]cehennem[/eluser]
Hello,

I have a simple login() function in my 'welcome' controller.

So with the help of default_controller, I can access 'welcome' controller and see my index() function by just entering 'http://www.mysite.com/' (index.php is hided)

but why this one doesn't work (while 'welcome' is my default_controller):

http://www.mysite.com/login (instead of http://www.mysite.com/welcome/login)

Thanks for helps,
Cheers.
#2

[eluser]dudeami0[/eluser]
Mind showing the code for the welcome controller?
#3

[eluser]cehennem[/eluser]
the result of mysite.com/login ;

404 Page Not Found
The page you requested was not found.

Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $veri['ses'] = $this->session->userdata('username');
        $this->load->view('welcome_message', $veri);
    }
    
    function logout() { $this->session->unset_userdata('username'); }
    
    function login () {
        $veri['gelen'] = $this->input->post('username');
        $this->session->set_userdata('username', $veri['gelen']);
        $veri['ses'] = $this->session->userdata('username');
        if ($veri['gelen'] != FALSE) $this->load->view('welcome_message', $veri);
    
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
#4

[eluser]LuckyFella73[/eluser]
Assuming that your login() function checks if the user
is logged in or not - be shure that you place the code
in the contructor, not in the index function. That way
the login-check is executed everytime the controller is
called no matter which method is called.

Quote:http://www.mysite.com/login (instead of http://www.mysite.com/welcome/login)

You got something wrong with the default controller option. The default
controller is just the controller that is called when you don't specify
a controller at all. By calling http://www.mysite.com/login you
call the login-controller (login.php) not the login-method of you
default controller!
#5

[eluser]cehennem[/eluser]
[quote author="LuckyFella73" date="1290093954"]Assuming that your login() function checks if the user
is logged in or not - be shure that you place the code
in the contructor, not in the index function. That way
the login-check is executed everytime the controller is
called no matter which method is called.

Quote:http://www.mysite.com/login (instead of http://www.mysite.com/welcome/login)

You got something wrong with the default controller option. The default
controller is just the controller that is called when you don't specify
a controller at all. By calling http://www.mysite.com/login you
call the login-controller (login.php) not the login-method of you
default controller![/quote]

so this means only way to get it work is routing it inside routes.php
#6

[eluser]dudeami0[/eluser]
I missed that part when reading your original post. Yeah, the best way to get yoururl.com/login to work is with routes. The default controller is just for no segments at all, so yoururl.com.
#7

[eluser]LuckyFella73[/eluser]
You can set up a is_the_user_logged_in class and call it
in every controllers constructor or better (in case you
have to check the login state in every controller)
extend the main controller and do the check there. By
extending the main controller you can define actions that
are called/executed everytime you access any of your controllers.

You can find a tutorial by Phil Sturgeon how to do that here:
http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY

There is a tutorial for the CI2 version available too at the same website.
#8

[eluser]cehennem[/eluser]
[quote author="dudeami0" date="1290094343"]I missed that part when reading your original post. Yeah, the best way to get yoururl.com/login to work is with routes. The default controller is just for no segments at all, so yoururl.com.[/quote]

well I thought default_controller will handle all functions in that controller. So I think default_controller acts like a simple route just to redirect the entrance of site.

it seems that route list will be bigger and bigger =p

thanks for answers.
#9

[eluser]LuckyFella73[/eluser]
Quote:So I think default_controller acts like a simple route just to redirect the entrance of site.

For your understanding about that:
In Codeigniter you call a controller that represents one or multipple
pages (depending on how many methods you have in it). If you want to
call a controller (Browser) you have to write the controller name
after the domain. The controller name has to be matched by a controller
file with the same name. If you just call the domain, codeigniter has
to know what controller should be called - that is meant ba default
controller.

But what I posted in my last thread should be a good way for you
(extending the main controller).
#10

[eluser]cehennem[/eluser]
[quote author="LuckyFella73" date="1290094549"]You can set up a is_the_user_logged_in class and call it
in every controllers constructor or better (in case you
have to check the login state in every controller)
extend the main controller and do the check there. By
extending the main controller you can define actions that
are called/executed everytime you access any of your controllers.

You can find a tutorial by Phil Sturgeon how to do that here:
http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY

There is a tutorial for the CI2 version available too at the same website.[/quote]

@luckyfella73, dudeami0;

thanks for all those valuable information that helped me a lot and made things clear! Wink




Theme © iAndrew 2016 - Forum software by © MyBB