[eluser]cartalot[/eluser]
looking for any suggestions, advice, etc on creating Libraries.
I know there are lots of ways of doing things - just looking for some input and best practices.
and if anyone has any suggested user CI libraries to look at
* what are best practices for returning from / getting data out of the Library -
for example i have a method in a library that gets a couple different db results
i'm assigning them to $data and returning $data
Code:
$data['cartitems'] = $this->_CI->phcartmodel->getCartItems($uid);
$data['cartotal'] = $this->_CI->phcartmodel->getCartfull($cid);
return $data;
it works but is this a mistake because $data is used in the controller?
* related - is it better to always return a value that can be checked -
or are there times when RETURN FALSE is enough?
* for development i am using something like this to keep track of the code and see where things are breaking
Code:
$this->devmessage .= 'Start update cart <br>';
and then outputting that in view -- which works fine across methods in the controller, but awkward for in and out of library.
suggestions?
* what is suggested best practice for declaring
Code:
$CI =& get_instance();
when i do this inside each method in the library it works fine.
but when i put it in the library constructor so i don't have to repeat it -- it does not work.
however when i use this version in the library constructor (and for example load the session class)
Code:
$this->_CI =& get_instance();
$this->_CI->load->library('session');
then i can use
Code:
$this->_CI->session->userdata('uid')
in any method in the library - which is fine but just wondering why.