Welcome Guest, Not a member yet? Register   Sign In
After running a method dinamically reload same page?
#1

[eluser]chefnelone[/eluser]
hello

I know this a simple task, but I can't figure it out how to do it.

In a Controller called 'site' I have a method like:
Code:
function languagesBackend(){
    
        
        //do something and..
        
        reload the view page where this method was called: in this case myPage.php.
        
    }

In myPage.php view:
Code:
<a href="&lt;? echo base_url();?&gt;site/languagesBackend">English</a>
When I click on the link 'English' it will run site/languagesBackend method.
Then, how do I do to reload myPage.php.?
I need to do it dynamically since this link could be placed anywhere.

thanks
#2

[eluser]Sbioko[/eluser]
First of all, you should get current page URL and simply refresh it using redirect. Read User Guide.
#3

[eluser]tunesmith[/eluser]
No, that doesn't work. current_url returns the url of the controller being called, not the url of the page it came from. redirect(current_url()) called from within a controller returns an infinite loop error.

You want to instead run current_url in the previous controller, and pass it as a parameter to the second controller. Then redirect to that parameter.
#4

[eluser]mddd[/eluser]
I think urls should be linked to pages. Not to actions that don't have a page attached to them.
In this case: what you want to do is perform some action and reload the page.
Why not make it so that clicking the link submits a form to the page you are already on.
The form could contain just a single POST variable. Like set_language = english.

You could extend the Controller (make a MY_Controller) that checks in its constructor to see
if $_POST['set_language'] is set. If so, run the 'languagesBackend' method. Then the controller
will continue on as normal. This way it works in every controller.

Alternatively you could put this functionality in a model and simply autoload it.




Theme © iAndrew 2016 - Forum software by © MyBB