Post by kagan » Thu Mar 17, 2016 11:20 pm

Hi all!

When I tried to create my own library with using database queries, I've got an error that I couldn't use a connection to the database.

Code: Select all

Notice: Undefined property: ShippingDelivery::$db in J:\home\techno\www\system\library\shippingDelivery.php on line 44
Fatal error: Call to a member function query() on a non-object in J:\home\techno\www\system\library\shippingDelivery.php on line 44
Before using my own library I added further code to include it in my project in the file "my_site/admin/index.php":

Code: Select all

$mylibr = new ShippingDelivery();
$registry->set('mylibrary', $mylibr); // +
Maybe anyone faced with this problem, as I can't find answer on my question..

User avatar
Newbie

Posts

Joined
Thu Mar 17, 2016 11:00 pm

Post by kagan » Tue Mar 22, 2016 2:21 am

I've done it!

Code: Select all

  require_once(DIR_SYSTEM . 'library/shippingDelivery.php');
  $delivery_library = new ShippingDelivery($registry);
  $registry->set('shipping_delivery', $delivery_library);
Thus we can use others throwing varible $registry.

And in our class we can use DB and other components:

Code: Select all

class shippingDelivery {
	private $db;
	private $config;
	private $cache;
	private $data = array();
	
	public function __construct($registry) {
		$this->db = $registry->get('db');
		$this->config = $registry->get('config');
		$this->cache = $registry->get('cache');
	}
	// Code
}

User avatar
Newbie

Posts

Joined
Thu Mar 17, 2016 11:00 pm
Who is online

Users browsing this forum: No registered users and 36 guests