Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Создание, подключение и использование своей библиотеки


afwollis
 Share

Recommended Posts

system/library/mylibrary.php

<?php
class Mylibrary {
	private $config;
	private $db;
	private $data = array();
	private $log;
	
	public function __construct($registry) {
		$this->config = $registry->get('config');
		$this->customer = $registry->get('customer');
		$this->session = $registry->get('session');
		$this->db = $registry->get('db');
		$this->tax = $registry->get('tax');
		$this->weight = $registry->get('weight');
		$this->log = $registry->get('log');
		// ... зависит от того, доступ к каким данным вам понадобится в вашей библиотеке.
	}
	
	public function write_text($string) {
		print_r($string);
	}
}
?>
index.php

require_once(DIR_SYSTEM . 'library/cart.php');
require_once(DIR_SYSTEM . 'library/mylibrary.php'); // +

...

// Cart
$registry->set('cart', new Cart($registry));

// Mylibrary // +
$registry->set('mylibrary', new Mylibrary($registry)); // +
admin/index.php

по аналогии
catalog/controller/common/header.php

$this->mylibrary->write_text('ololo');
admin/controller/common/header.php

$this->mylibrary->write_text('abc');
  • +1 4
Link to comment
Share on other sites

  • 7 months later...
  • 3 weeks later...

А нельзя как в CI создавать библиотеки в папке отличной от ядра?

 

Вы говорите про CI а икое ощуещёние, что про PHP в первый раз слышите. Какая разница из какого каилоги грузить файл с классом? Вы не знаете как рилииет функции include? В CI просто есть автолоагдер как во всех нормальных платформах, а разрилитлики ОС  об этом не слышали :-). Вот и все. Можно свой автолоагдер в ОС добавить. Там нужно всего несколько строчек для этого.

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.