[eluser]Krumpet[/eluser]
I'm not sure if this problem represents my basic knowledge of CI or my basic knowledge of OOP. Hopefully, we'll find out...
What I'm trying to do is create a Fetch object to retrieve XML feeds. Users will be able to choose from a few different options to define the feed they want to return. Their choices are passed to the Search class where they are placed in a new Params object and then the Params object is passed into the Fetch class which will return the feed in array format - when I get this done.
Where I'm confused is with the Fetch __construct. First, is it 'good OOP form' to pass values into a class during object creation? Second, how is this approach affected by autoloading the class?
Here is the code for the Search class (poorly named, I know) and the Fetch class (incomplete). I've also included the error I'm getting. Thanks!
Code:
class Search extends CI_Controller{
public function index()
{
$this->config->load('program');
$this->load->library('params');
$this->load->library('fetch');
$params = new Params($_GET['username'],$_GET['feed'],$_GET['locale']);
$fetch = new Fetch($params);
}
}
Code:
class Fetch {
protected $_url;
protected $_remotefile;
protected $_error;
protected $_urlParts;
public function __construct($params)
{
/*
/ receive url, pass to setURL method and store in protected variable
*/
$this->setURL($params);
/*
/ validate URL
*/
$this->checkURL();
/*
/ check each connection option and choose between direct access, cURL access, or socket access
*/
if (ini_get('allow_url_fopen')){
$this->_remoteFile = getInstance('direct');
} elseif (function_exists('curl_init')){
$this->_remoteFile = getInstance('curl');
} else {
$this->_remoteFile = getInstance('socket');
}
}
The error I am getting is as follows:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Fetch::__construct(), called in /Users/ryanodonnell/Sites/affiliates/system/core/Loader.php on line 950 and defined
Filename: libraries/Fetch.php
Line Number: 9