[eluser]Renato Tavares[/eluser]
Whenever I create my own library is necessary to invoke it through an array? Let me explain:
In my library I have to pass only a code of 13 digits every time I call. In the documentation there is only examples of arrays, to work around that I am using the following syntax:
Controller calling the library:
Code:
[other things....]
$object = 'SW449086657BR';
$this->load->library('correios', array($object));
$data = $this->correios->result;
$this->load->view('actions/tracking', $data);
[other things....]
receiving data from controller in library
Code:
public function __construct($object) {
$object = strtoupper($object[0]);
if (preg_match('/^[a-zA-Z]{2}[0-9]{9}[a-zA-Z]{2}$/', $object)) {
$this->search($object);
} else {
$this->result['erro'] = 'Objeto inválido';
}
}
[other things....]
I did not think this the most elegant solution, it is possible to improve?
I tried to pass off an array and did not work