ken.lau 发表于 2016-4-29 10:00:25

关于CI教程中上传部分的问题请教

<?php
/*constructor function to initialize controller and load the file upload class, plus the two other helpers it needs */
class Upload extends Controller {
    function Upload()
    {
          parent::Controller();
          $this->load->helper(array('form', 'url'));
          $this->load->library('upload');
    }
/*now the function which does all the work!*/
function do_upload()
   {
          if ( ! $this->upload->do_upload())
          {
               $error = array('error' =>
                                     $this->upload->display_errors());
               
               $this->load->view('upload_form', $error);
          }      
          else
          {
               $data = array('upload_data' =>
                                             $this->upload->data());
               $this->load->view('upload_success', $data);
          }
   }      
}

以上为从教程上复制过来的程序
请教:
if ( ! $this->upload->do_upload())
这一句会调用自身,自身的开始又是这一句,还是会再调用一次自身产生一个新的实例。我理解的会一直递归下去

一叶扁舟 发表于 2016-4-29 13:43:52

调用自身是这样$this->do_upload(),$this->upload->do_upload()是调用upload类的do_upload()方法

ken.lau 发表于 2016-4-29 14:33:35

一叶扁舟 发表于 2016-4-29 13:43
调用自身是这样$this->do_upload(),$this->upload->do_upload()是调用upload类的do_upload()方法 ...

是我没表达清楚,是调用do_upload方法;我就是想不明白方法定义中就是调用方法自己这不是递归嘛?
页: [1]
查看完整版本: 关于CI教程中上传部分的问题请教