MVC pattern and $_POST variables
I am building a php/mysql based framework and cms , and I got stucked into passing variables using post method , from a form located in one controller, to another controller. More exactly , i built a form for changing languages. this form is located in localhost/index/index, and when I select a language, it goes to http://localhost/application/change_language, where change_language is a public function in application class. The thing is that $_POST variables from开发者_JAVA百科 that form, don't get through , to change_language function. I var_dump-ed the entire $_POST tree, in this function, and all I got is array(0) { }. What I am doing wrong, or why isn't this working? Sorry for my english . Cheers
Sounds like you could use sessions to carry your data over. I ran into this problem with CodeIgniter and post data. I created a session with the post data, worked like a champ.
Could be a variety of things that are going wrong, it will be best to post some code here so we can have a look at what is wrong instead of blindly guessing what might be wrong.
Although as first look, it sounds like you did not properly post the form values to the function change_language. Please check that the form is properly formed. You might want to have a look at this.
In the MVC's perspective, form should be inside View not the Controller. So i would suggest you to put the form inside a View and then specify the action attribute of the form to a Controller which will process the form request something like this:
<form name="myform" method="post" action="index.php/your_controller">
.... more stuff here
</from>
Now you code for the your_controller Controller to process the form request:
class your_controller extends whateverparentcontroller
{
print '<pre>';
print_r($_POST);
}
精彩评论