Codeigniter - change url at method call

Posted by NemoPS on Stack Overflow See other posts from Stack Overflow or by NemoPS
Published on 2012-09-28T21:35:33Z Indexed on 2012/09/28 21:37 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

I was wondering if the following can be done in codeigniter.

Let's assume I have a file, called Post.php, used to manage posts in an admin interface. It has several methods, such as index (lists all posts), add, update, delete... Now, I access the add method, so that the url becomes

/posts/add

And I add some data. I click "save" to add the new post. It calls the same method with an if statement like "if "this->input->post('addnew')"" is passed, call the model, add it to the database

Here follows the problem: If everything worked fine, it goes to the index with the list of all posts, and displays a confirmation

BUT

No the url would still be posts/add, since I called the function like $this->index() after verifying data was added. I cannot redirect it to "posts/" since in that case no confirmation message would be shown!

So my question is: can i call a method from anther one in the same class, and have the url set to that method (/posts/index instead of /posts/add)?

It's kinda confusing, but i hope i gave you enough info to spot the problem

Cheers!

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about url