Welcome Guest, Not a member yet? Register   Sign In
Loading controllers from within controller
#1

[eluser]sanguina[/eluser]
How do i load a controller from within a controller.

For example,

I am using tank_auth library which has a controller called auth which calls a view called login_form to display the login form page.

Now I want to display this login form in the top of the homepage.

the home page is displayed by another controller called home_controller

how do i call the auth controller from the home-controller.

Please help

#2

[eluser]pisio[/eluser]
from home_controller to call method in it with him ?
Code:
class  home_controller  extends ci_controller {

  function methodOne()
{
echo "....";
}

function methodTwo()
{
echo "aaa";
}

function index()
{
$this->methodOne();
$this->methodTwo();
echo " bbbb";
}

}

If i udenterstand you corectly
#3

[eluser]sanguina[/eluser]
thanks for replying..


but what if my method one is already present in say b_controller .. do i have to write the method one again in home-controller.

isn't there a way i can call method one in b_controller from home_controller ?

#4

[eluser]Mirge[/eluser]
I believe he's wanting to call a different controller's method from the current controller. I think that's what HMVC allows?

<waits patiently for someone more experienced in that area to respond....*cough* cronix, insite..>
#5

[eluser]sanguina[/eluser]
yes precisely what i wanted. a search on HMVC lead me to some articles - but i dont think - i need to go all the way to create spearate M-V-C for each module.

What i am asking for is an everyday phenomena on websites - including the way its displayed here at the top of this forum.

All i want is to display the login form at the top of each page and if the user is logged the form is replaced by some welcome message - like "Hello Username".

thanks a lot - i am new to ci - read through most of the tutorials - but nothing that came close to answering this issue.
#6

[eluser]ppwalks[/eluser]
why not just define the is_logged_in method from the auth library and echo the difference if that makes sense
#7

[eluser]NeoArc[/eluser]
Create a base controller in the application/core/ directory:

Code:
&lt;?php
class MY_Controller extends CI_Controller{

    function _head(){
        //...
    }
}


_head() will be available in all descendants of MY_Controller

Code:
class Blog extends MY_Controller{

    function hello(){
        $this->_head();
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB