codeigniter 4路由查询

hi3rlvi2  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(144)

这是我的函数

public function check()
{   
    $data = [
                'pageTitle' => 'Documents Check',
                'action' => 'check',
                'validation' => NULL,
    ];
    
    if($this->request->getMethod() == 'post'){

        $validation = $this->validate([
            'jobNo' => [
                        'rules' => 'required|numeric|exact_length[6]|is_not_unique[docs.Job_no]',
                        'errors' => [
                               'required' => 'Job No. required.',
                               'exact_length' => 'Job No. should be exactly 6 digits.',
                               'numeric' => 'Job No. should be numbers only.',
                               'is_not_unique' => 'No files available for entered Job No.',
                           ]    
                      ],
        ]);
        if($validation){
            $jobNo = $this->request->getVar('jobNo',FILTER_SANITIZE_STRING);
            $data['docs'] = $this->docsModel->getDocsByJob($jobNo);
            return view('documents/files_display',$data);
        }
        else{
            $data['validation'] = $this->validator; 
        }  
        
    } // post

   return view('documents/files_view',$data);
} // check

文件_显示外观
| 标识符|工单号|文件|作用|
| - -|- -|- -|- -|
| 一个|小行星23233| invoice.pdf |除去了|
| 2个|小行星23233| deliver.pdf |除去了|

public function remove($id){        
    if($this->docsModel->delete($id);){
            return redirect()->back()->with('success','file removed from the Job record');
        }
}

所以在这里redirect()-〉back()或current_url()把我带到页面,在那里我必须再次输入“工作号”的形式.我所寻找的是留在file_display页面上点击删除.

qyuhtwio

qyuhtwio1#

也许可以使用Session

public function check()
{   
    $data = [
                'pageTitle' => 'Documents Check',
                'action' => 'check',
                'validation' => NULL,
    ];
    
    if($this->request->getMethod() == 'post'){

        $validation = $this->validate([
            'jobNo' => [
                        'rules' => 'required|numeric|exact_length[6]|is_not_unique[docs.Job_no]',
                        'errors' => [
                               'required' => 'Job No. required.',
                               'exact_length' => 'Job No. should be exactly 6 digits.',
                               'numeric' => 'Job No. should be numbers only.',
                               'is_not_unique' => 'No files available for entered Job No.',
                           ]    
                      ],
        ]);
        if($validation){
            $jobNo = $this->request->getVar('jobNo',FILTER_SANITIZE_STRING);
            $data['docs'] = $this->docsModel->getDocsByJob($jobNo);
            
            //Save jobNo to SESSION
            session()->set('jobNo', $jobNo);
            
            return view('documents/files_display',$data);
        }
        else{
            $data['validation'] = $this->validator; 
        }  
        
    } // post

   // Add GET method condition, and if there is jobNo in session
   if($this->request->getMethod() == 'get' && session->has('jobNo')){
       $jobNo = session()->get('jobNo');
       $data['docs'] = $this->docsModel->getDocsByJob($jobNo);
       return view('documents/files_display',$data);
   }

   // Remove Session when accessing FORM (Optional)
   // session()->remove('jobNo');
   
   return view('documents/files_view',$data);
} // check

相关问题