私はいくつかの提案が必要なアプリケーションを開発しています。問題の詳細は次のとおりです。
public function form()
{
$this->load->helper('inflector');
$id = $this->uri->segment(3,0);
if($data = $this->input->post()){
$result = $this->form_validation->run();
if($result){
if($id > 0){
// here update code
}else{
$this->mymodel->insert($data);
$this->session->set_flashdata('message','The page has been added successfully.');
$this->redirect = "mycontroller/index";
$this->view = FALSE;
}
}else{
//$this->call_post($data);
$this->session->set_flashdata('message','The Red fields are required');
$this->view = FALSE;
$this->redirect = "mycontroller/form/$id";
}
}else{
$row = $this->mymodel->fetch_row($id);
$this->data[]= $row;
}
}
public function _remap($method, $parameters)
{
if (method_exists($this, $method))
{
$return = call_user_func_array(array($this, $method),$parameters);
}else{
show_404();
}
if(strlen($this->view) > 0)
{
$this->template->build('default',array());
}else{
redirect($this->redirect);
}
}
ここでは、検証に失敗したときにページをリロードしようとしている方法を確認できます。ここで問題となるのは、リダイレクト後にのみ使用できるビューフォームにフラッシュデータを表示する必要があり、post変数が失われたためにリダイレクト時に表示されない検証エラーを表示する必要があることです。リダイレクトを使用しない場合、flashdataを表示できませんが、検証エラーのみを表示できます。両方の機能をまとめてほしい。このようにもう一度POStを作成してみました
public function call_post($data)
{
foreach($data as $key => $row){
$_POST[$key] = $row;
}
}
これをformmethodでコメントアウトしました。どうすればこれを実現できますか。