用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1021|回复: 2
收起左侧

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

[复制链接]
发表于 2016-4-29 10:00:25 | 显示全部楼层 |阅读模式
<?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()方法
 楼主| 发表于 2016-4-29 14:33:35 | 显示全部楼层
一叶扁舟 发表于 2016-4-29 13:43
调用自身是这样$this->do_upload(),$this->upload->do_upload()是调用upload类的do_upload()方法 ...

是我没表达清楚,是调用do_upload方法;我就是想不明白方法定义中就是调用方法自己这不是递归嘛?

本版积分规则