Vito
Vito

Reputation: 728

Executing method before loading view in CodeIgniter

I have an application on CodeIgniter that generate a PDF report using some information. Before doing that, I need to execute a function in a controller to save data on the database. I called the methods on the controller using JavaScript. How can I call the function before redirecting to the PDF controller? I have this:

    window.open("codeIgniterURL/Controller1/function1",'_self',false);
    window.open("codeIgniterURL/Controller2/function2",'_self',false);

So what I need to do, is to call a function of controller1 within a view before opening the Window of Controller 2. What I do now is to open the Controller1 with a window.open, and in that controller redirect to the view where I invoked the method, but its not working like I need.

Any help is really appreciated.

Upvotes: 0

Views: 530

Answers (1)

tsg
tsg

Reputation: 205

If this helps, I accomplished this by using two controllers, a model, and an Ajax call.

In Controller 1, I have the code that writes the PDF.

Controller 2 makes the call to the model to write to the database. Then it instantiates Controller 1, uses ghostScript to create an image of the generated PDF, and sets the name of the PDF in a session variable.

In my view, I use Ajax to send the post data to Controller 2, then, using the session variable, it dynamically displays the image created and a download button for the PDF.

Upvotes: 1

Related Questions