开发者

Trouble extending library in CodeIgniter

开发者 https://www.devze.com 2022-12-21 19:37 出处:网络
I am trying to extend the Upload library in CodeIgniter. I have been trying all morning, following various tuts and forum posts, but can\'t get it to work.

I am trying to extend the Upload library in CodeIgniter. I have been trying all morning, following various tuts and forum posts, but can't get it to work.

If I add the function I want directly into the Upload.php library, it works-- but I know this isn't the right way, and want to do it right since I'm doing it.

Here is the content of the extension [system/application/libraries/MY_Upload.php]:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class MY_Upload extends Upload{
function MY_Upload(){
    parent::Upload();
}
  function mupload($configs,$files){
    if(count($configs) != count($files)){
       return 'array_count_wrong';
    }
$retArr=array();
    for($i=0, $j = count($files);$i<$j;$i++){
        $this->initialize($configs[$i]);
        if(!$this->do_upload($files[$i])){
            array_push($retArr,$this->display_errors());
        }else{
            array_push($retArr,'OK');
        }
    }
   开发者_如何学JAVA return($retArr);
}

?>

And relevant controller code:

$this->load->library('upload');
$messages=$this->upload->mupload($config,$files);

It fails with no indication of why.

What am I doing wrong?

Thx.


Missing a friggin } at the end of the extension

:'(

I REALLY REALLY REALLY wish there was a way to get more informative error messages (or any message at all) when things fail...


A few extra bits of advice here.

  1. You should extend from CI_Upload not Upload
  2. You only need to add a contructor with parent::CI_Upload; if you are actually doing something in your controller. Delete function MY_Upload() as you don't need it. :-)

Glad you solved your main problem though!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号