EllisLab text mark
Advanced Search
     
Trouble extending CI library with a spark
Posted: 10 May 2012 12:04 AM
Joined: 2012-05-09
1 posts

I’m trying to add a few functions to the CI_FTP FTP library by extending it. I’m doing this as part of a spark, but when I load the spark, my extensions don’t seem to take.

I created this file in sparks/myspark/0.0.1/libraries/MY_Ftp.php

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

/**
 * FTP Library Extensions
 *
 * Adding some useful functions to the built-in CI FTP library
 *
 * @package   CodeIgniter
 * @subpackage Libraries
 * @category  Library
 */

class MY_FTP extends CI_FTP {
 
public function __construct() {
     parent
::__construct();
 
}

 
/**
  * Get remote file size
  *
  * @access public
  * @param  string
  * @return integer
  */
 
function file_size($filepath)
 
{
  
if ( ! $this->_is_conn())
  
{
   
return FALSE;
  
}

  
return @ftp_size($this->conn_id$filepath);
 
}

 
/**
  * Get remote file modification time
  *
  * @access public
  * @param  string
  * @return integer (time)
  */
 
function file_mdtm($filepath)
 
{
  
if ( ! $this->_is_conn())
  
{
   
return FALSE;
  
}

  
return @ftp_mdtm($this->conn_id$filepath);
 
}

But when I load the spark, and load the ftp library, my new methods aren’t there:

$this->load->spark('myspark/0.0.1');
var_dump(method_exists($this->ftp'file_size'));
// bool(false) 

When I copy MY_Ftp.php into my application/libraries folder instead, everything works as expected.

Can sparks not override/extend CI libraries? Am I doing it wrong?

 

 
Posted: 19 May 2012 05:19 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-08-17
3 posts

I’ve got the same issue exactly like for timchambers but with helpers.

Building a spark for language, I need to override site_url() which is only possible through

sparks/myspark/x.x.x/helpers/MY_url_helper.php

.

At running time it’s just simply ignored.

If I copy MY_url_helper.php to application/helpers, it works perfectly.

It’s not a big deal, but it seems that the CI override mechanism doesn’t extend to sparks.

Maybye this will work with sparks integration planned for a next CI version ...