Welcome Guest, Not a member yet? Register   Sign In
Is it possible for one controller/method to call another controller/method?
#3

(This post was last modified: 07-24-2015, 05:20 PM by ivantcholakov.)

It is possible. The easiest method I can describe is when it happens within the same class.

Code:
class Bar extends CI_Controller {

    public _construct {
        ...
    }

    public function original_post {

        $post = $this->input->post();

        if (!empty($post['condition'])) { // Some condition for switching to an alternative method.

            $this->alternative_post();

            return; // Don't forget this.
        }

        $data = array(/*...*/); // Other data.

        $this->load->view('original_post_view', $data); // $_POST data is accessible in the view through form_helper functions set_value(), etc.
    }

    function alternative_post() { // Or named as _alternative_post if we don't want this method to be accessed bi the browser.

        //$post = $this->input->post(); // If this is needed.

        $data = array(/*...*/);

        $this->load->view('alternative_post_view', $data);
    }

}

If the alternative method by some important reason is to be inside a different controller, then I can imagine using the modular extensions by wiredesignz. But I am lazy to write code for that, you can, I am sure. PS: Be careful how the second controller initializes.
Reply


Messages In This Thread
RE: Is it possible for one controller/method to call another controller/method? - by ivantcholakov - 07-24-2015, 05:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB