2016-11-05 6 views
0

누구든지 도움을받을 수 있습니다. 나는 더러운 코드를 최소화하고 싶다. 나는 논리가 약하다. 사전에 감사합니다 ..PHP 코드를 최소화하는 방법

//These are all fields 
$prodname = $this->input->post('prodname'); 
$price = $this->input->post('price'); 
$qty = $this->input->post('qty'); 
$desc = $this->input->post('desc'); 
$status= $this->input->post('status'); 


// This part I want to minimize, or any shorthand for this code?? 
if ($prodname != NULL && $price != NULL && $qty != NULL && $desc != NULL && $status != NULL) 
    $datas = $this->controller->add_product($data); 
+1

가에 질문을 게시 http://codereview.stackexchange.com/ – sTg

+0

이것이 양식에서 오는 경우. 그렇다면, codeigniters form_validation을 사용하면 폼 팩터에서 제공된 데이터가 사용자가 원하는 것임을 보장하기 위해 유효성 검사를 추가 할 수 있습니다. – TimBrownlaw

답변

1

예는이 다음을 수행 할 수

//These are the fields coming from form "username" is the name of field 

$this->form_validation->set_rules('username', 'Username', 'required'); 
$this->form_validation->set_rules('password', 'Password', 'required'); 
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required'); 

을 추가 할 많은 규칙을 추가 한 다음 그냥이 검증 않다면 확인하려는 여부, 이것을 사용 :

if ($this->form_validation->run() == FALSE) 
{ 
    $this->load->view('myform'); 
} 
else 
{ 
    $this->load->view('formsuccess'); 
} 

참조 : https://www.codeigniter.com/userguide3/libraries/form_validation.html

+0

감사합니다. Bro @Habib ........ 지금 작동 중입니다. – Marky

관련 문제