• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controllers

#1
[eluser]marcin346[/eluser]
Hello. I’m new ‘coder’ form Poland.
How can I use function from controller A in controller B ?
For example:
site.php:
...........
...........
...........
function check_login()
{
IF($cookie = $this->input->cookie(‘cicookie’, True))
{
$dane = unserialize(base64_decode($cookie));
IF(is_array($dane))
{
$a = $this->User;
$b = $a->get_user_by_login($dane[‘user’]);
$ar = $b->result_array();
IF(isset($ar[0]) and $ar[0][‘user_last_login_ip’] == $this->input->ip_address() and sha1(md5($ar[0][‘user_login’].$ar[0][‘user_password’])) == $dane[‘pass’])
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
...................................................
...................................................

add_news.php:

..........................
..........................
function add()
{
check_login();
......................
....................
....................
......................
}
...................................
...............................
...........................

I need to get username before post a article.

#2
[eluser]Atharva[/eluser]
You should use code blocks for writing your code.

Second thing, after login, you can store whatever values you will need in session (userid, name etc.)

Finally, You can check whether user is logged in or not by writing something like
Code:
function Dashboard()
    {
        parent::Controller();
        
        if(!$this->session->userdata('userID'))
        redirect('home/login','location');
    }

in your constructor of each controller that only logged in user can access.

Hope that helps.

#3
[eluser]InsiteFX[/eluser]
Read this:

CodeIgniter Base Classes: Keeping it DRY

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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