如何检查是否在codeigniter处使用switch切换变量

时间:2013-11-28 13:30:15

标签: php codeigniter php-5.3

我发布表单输入,但我想要的,如果一些输入不发布做这个代码(...) 我使用开关来做这个并且isset和空...但它不能正常工作......为什么

 function create (){

                // create word file
                $this->load->library('PHPWord');
                $case_num1 = $this->input->post('case_num1');
                $case_num2 = $this->input->post('case_num2');
                $case_num3 = $this->input->post('case_num3');
                $case_date = $this->input->post('case_date');
                $case_subject = $this->input->post('case_subject');
                $case_system = $this->input->post('case_system');
                $case_brief = $this->input->post('case_brief');
                $case_facts = $this->input->post('case_facts');
                $case_reasons = $this->input->post('case_reasons');
                $case_staffs = $this->input->post('case_staff');

                $this->word_validation_input($case_num1,$case_num2,$case_num3,$case_date,$case_subject,$case_system,$case_brief,$case_facts,$case_reasons,$case_staffs);

}  


 function word_validation_input($case_num1,$case_num2,$case_num3,$case_date,$case_subject,$case_system,$case_brief,$case_facts,$case_reasons,$case_staffs) {
        switch (isset($case_subject,$case_system,$case_brief,$case_facts,$case_reasons,$case_staffs) ) {
            default :
                $document = $this->phpword->loadTemplate('application/docs/temp/temp-grey/Template.docx');
                $document->setValue('Value1', "$case_num1");
                $document->setValue('Value2', "$case_num2");
                $document->setValue('Value3', "$case_num3");
                $document->setValue('Value4', "$case_date");
                $document->setValue('Value5', "$case_subject");
                $document->setValue('Value6', "$case_system");
                $document->setValue('Value7', "$case_brief");
                $document->setValue('Value8', "$case_facts");
                $document->setValue('Value9', "$case_reasons");
                $document->setValue('Value10', "$case_staffs");
                $document->save('./global/uploads/ahkam.docx');
            case empty($case_subject):
                $document = $this->phpword->loadTemplate('application/docs/temp/temp-grey/Template_1.docx');
                $document->setValue('Value1', "$case_num1");
                $document->setValue('Value2', "$case_num2");
                $document->setValue('Value3', "$case_num3");
                $document->setValue('Value4', "$case_date");
                $document->setValue('Value6', "$case_system");
                $document->setValue('Value7', "$case_brief");
                $document->setValue('Value8', "$case_facts");
                $document->setValue('Value9', "$case_reasons");
                $document->setValue('Value10', "$case_staffs");
                $document->save('./global/uploads/ahkam.docx');
                break;
            case empty($case_system):
                $document = $this->phpword->loadTemplate('application/docs/temp/temp-grey/Template_2.docx');
                $document->setValue('Value1', "$case_num1");
                $document->setValue('Value2', "$case_num2");
                $document->setValue('Value3', "$case_num3");
                $document->setValue('Value4', "$case_date");
                $document->setValue('Value5', "$case_subject");
                $document->setValue('Value7', "$case_brief");
                $document->setValue('Value8', "$case_facts");
                $document->setValue('Value9', "$case_reasons");
                $document->setValue('Value10', "$case_staffs");
                $document->save('./global/uploads/ahkam.docx');
                break;
            case empty($case_brief):
                $document = $this->phpword->loadTemplate('application/docs/temp/temp-grey/Template_3.docx');
                $document->setValue('Value1', "$case_num1");
                $document->setValue('Value2', "$case_num2");
                $document->setValue('Value3', "$case_num3");
                $document->setValue('Value4', "$case_date");
                $document->setValue('Value5', "$case_subject");
                $document->setValue('Value6', "$case_system");
                $document->setValue('Value8', "$case_facts");
                $document->setValue('Value9', "$case_reasons");
                $document->setValue('Value10', "$case_staffs");
                $document->save('./global/uploads/ahkam.docx');
                break;
            case empty($case_facts):
                $document = $this->phpword->loadTemplate('application/docs/temp/temp-grey/Template_4.docx');
                $document->setValue('Value1', "$case_num1");
                $document->setValue('Value2', "$case_num2");
                $document->setValue('Value3', "$case_num3");
                $document->setValue('Value4', "$case_date");
                $document->setValue('Value5', "$case_subject");
                $document->setValue('Value6', "$case_system");
                $document->setValue('Value7', "$case_brief");
                $document->setValue('Value9', "$case_reasons");
                $document->setValue('Value10', "$case_staffs");
                $document->save('./global/uploads/ahkam.docx');
                break;
            case empty($case_reasons):
                $document = $this->phpword->loadTemplate('application/docs/temp/temp-grey/Template_5.docx');
                $document->setValue('Value1', "$case_num1");
                $document->setValue('Value2', "$case_num2");
                $document->setValue('Value3', "$case_num3");
                $document->setValue('Value4', "$case_date");
                $document->setValue('Value5', "$case_subject");
                $document->setValue('Value6', "$case_system");
                $document->setValue('Value7', "$case_brief");
                $document->setValue('Value8', "$case_facts");
                $document->setValue('Value10', "$case_staffs");
                $document->save('./global/uploads/ahkam.docx');
                break;
            case empty($case_staffs):
                $document = $this->phpword->loadTemplate('application/docs/temp/temp-grey/Template_6.docx');
                $document->setValue('Value1', "$case_num1");
                $document->setValue('Value2', "$case_num2");
                $document->setValue('Value3', "$case_num3");
                $document->setValue('Value4', "$case_date");
                $document->setValue('Value5', "$case_subject");
                $document->setValue('Value6', "$case_system");
                $document->setValue('Value7', "$case_brief");
                $document->setValue('Value8', "$case_facts");
                $document->setValue('Value9', "$case_reasons");
                $document->save('./global/uploads/ahkam.docx');
                break;
          }
    }

1 个答案:

答案 0 :(得分:1)

switch(true)
{
  case ($case_subject == '' ):
    echo "set ur contition";
    break;
  case ($case_system == '' ):
    echo "set ur contition";
    break;
  default:
    echo "set default condition";
    break;
}

请申请。