Яндекс.Метрика
qr-код - Как-то так стрелка - Как-то так
Ведущий экономист + ... пиктограмма - Как-то Так THIS     Экономическая грамотность и web-решения
Будь в курсе: что, как и почему. Актуальные вещи - своими словами.
Повышайте своё качество с нами - СПЭМ !
If you don't like what you get, change what you give. © Carlos Castaneda     KAKTOTAK.BY - услуги по экономическому проектированию и web-разработке (php/js - telegram, WordPress, Laravel, Vue, SEO)    Cooperation - on an ongoing basis    Be in the topic   -    SUBSCRIBE      My notes are ECONOMICS +  и  Справочник WEB-разработчика | php+js+seo   в Telegram   telegram  

How to connect a third-party PHP library using COMPOSER to an engine-based website (CMS)

How to connect a third-party PHP library using COMPOSER to an engine-based website (CMS)

Many sites/ projects, in order not to reinvent the wheel, are more convenient to do on ready-made php – CMS platforms (WordPress, Bitrix from 1C, Joomla, OpenCart, ImageCMS, etc.). Well, or, to give more flavor and a certain independence, on one of the frameworks (Laravel, Symfony, CodeIgniter and etc.).

Of course, we are talking about a development environment using the server-side programming language PHP.

The main advantage in using the most popular CMS is the possibility of expanding their functionality by developing their own scripts, connecting third-party libraries with their integration into the file environment of the engine itself.

In other words, we developed our own script/program in PHP, or took a string library (from other developers) and integrated it into the body of our engine (CMS) to interact with the functionality of your project and return the result of its work to the CMS page template.

In this post, we will talk exactly about how to connect a third-party library developed in PHP (Packagist standard) to your CMS project using the popular PHP dependency manager COMPOSER.

To understand how you can customize all this interaction, taking into account the specific needs of the developer in solving a specific task, let's give a simple example.

Since almost all popular CMS are based on OOP (object-oriented programming) approaches and their file structure is similar, the general approaches in implementing this task for all CMS (WordPress, Bitrix, Joomla, Drupal, etc.) will be similar.

We have a website based on the ImageCMS engine (CodeIgniter framework) and we need to implement such a simple task.

On our site, using the functionality of the engine (admin panel), we will create a regular page on which, having previously created additional fields for uploading two images (through the entire admin panel), we will output them in png format, and based on them we will generate one image in the gif format (in two variations).

The creation of the page and the output of the source images on it will be achieved using the standard administrative procedure for managing the engine(CMS), but a third-party library will help us in creating gif images (animations) on the same page.

In this example, we will connect the necessary library in two ways, with the output of the result of each of them in two areas of the page:

  • 1 using the filefunctions.php , located at the root of the theme of the engine (used to expand its functionality)
  • 2 –lib_gif library created by us in the body of the framework itself(codeigniter) engine(ImageCMS) (in the application/ libraries folder)

It remains to find the necessary library in PHP to solve the task.

There is such a wonderful resource https://packagist.org , where developers from all over the world place and share their software scripts (libraries), thereby facilitating the development process for other programmers.

Packagist is a repository of Composer packages. It allows you to find packages and tells Composer where to get the code from. Any developer can use Composer to manage their project or library dependencies.

Composer, in turn, is a popular PHP dependency manager that simplifies the process of installing and updating project dependencies (some analogue of NodeJS NPM).

He facilitates the installation, via the command line of his terminal/console, of all necessary versions of packages in accordance with the request of the developer.Among other things, Composer is often used to install new projects built on such popular PHP frameworks as Laravel and Symfony on its local server.

And so, we go to the site https://packagist.org and we are looking for something similar to solve our problem creating gif animations.

how to connect a third-party PHP library using COMPOSER to a site on the engine (CMS) - 1

We find the library we need - pomirleanu/gif-create

We familiarize ourselves with the instructions for its installation and use.

how to connect a third-party PHP library using COMPOSER to an engine site (CMS) - 2

how to connect a third-party PHP library using COMPOSER to a site on the engine (CMS) - 3

Before we start installing pomirleanu/gif-create, we need to install it on our system first (in this case Windows) compser, in order to ensure that this library is loaded and connected to our project via the command line.

Since we have a local development environment on the Oep Server (OS), composer is already installed in the system by default along with the OS.

The only thing we will do is add for our convenience and the ability to work with it not only through the OS console, but also Visual Studio Code, which is our code editor (IDE - integrated development environment). Or, in other words, make friends with the VS Code console and OpenServer.

We do the following in the OS settings:

how to connect a third-party PHP library using COMPOSER to a site on the engine (CMS) - 5

how to connect a third-party PHP library using COMPOSER to a site on the engine (CMS) - 6

If your development environment is not on OS (but, for example, on XAMPP, WAMP, or separately plug-in PHP, etc.), then composer must be installed globally. Just download and run installer for Windows.

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 7

To check the installed version of composer in the terminal command line, enter:

composer –v

and we will get all the service information on it

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 8

Next, we will create a folder app_packagist (any name can be set) in the root of the project, into which we will download the necessary library using composer.

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 9

Go through the VS Code console to this folder and run the following command:

composer require pomirleanu/gif-create

how to connect a third-party PHP library using COMPOSER to a site on the engine (CMS) - 4

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 10

After that, the app_packagist will be created in the folder:

  • the composer.json file, where the plug-in package (name/version) is specified.
  • the composer.lock file, where all installed dependencies and their versions are specified.
  • and the vendor folder with the downloaded main and dependent packages (libraries)

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 11

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 12

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 13

If we had originally created a file composer.json in the app_packagist folder and specified a construction in it as an object require:

and after that we made a request:

composer install

then we got the same result.

In fact, the same as with the composer require pomirleanu/gif-create request, only with the first option, the composer.json file is created automatically if it was not in the folder before.

In the vendor folder, we see all the basic and auxiliary packages needed to create gif animations from png images.

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 14

Creating a page (my_page) of your site using the CMS admin panel:

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 15

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 16

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 17

We attach the output template of this page to the created file my_page.tpl, where we output our original images (/uploads/1.png and /uploads/2.png)

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 18

Let's see what we've got.

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 18_1

Below, on the same page, we will display the result of the connected library pomirleanu/gif-create.

To do this, in the file of the created template (my_page.tpl) of our page, we will write the following code, which will be responsible for the output of animation in two variants.

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 19

1. using the created gif function in the file functions.php :

{site_url(gif($image_1,$image_2))} – url of the first animation

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 20

2 using the created lib_gif library (in the application/ libraries folder):

{$url_animated = $CI->load->library('lib_gif')->index($image_1,$image_2)}

{site_url($url_animated)} - url of the second animation

In fact, the code is identical inside the index() method.

how to connect a third-party the PHP library using COMPOSER to the site on the engine (CMS) - 21

The difference between the first animation and the second is that the array $frame, which is the first argument of the method being called (->create($frames, $durations)) of the class object (new GifCreate\GifCreate()) in the 1st method includes the first element url = /uploads/1/png, and in the 2nd second url = /uploads/2.png.

Therefore, the alternation of the original images in the generated animation in the 1st and 2nd versions will be different for us.

how to connect a third-party PHP library using COMPOSER to an engine site (CMS) - 22

This is how you can configure the interaction of the CMS with any external library installed using composer, as part of your project for the synthesis, processing and output of certain data, including on pages created directly by the engine itself (CMS).

By understanding how to use one or another library from the Composer package repository in your projects, you can significantly simplify the development process itself, especially since today most of all sites /resources, after all, are developed on ready-made php platforms (CMS).  

How to connect a third-party PHP library using COMPOSER to an engine-based website (CMS) - Something like that!

автор - Михаленко Р.
M R. Автор - kaktotak.by Специализация: финансово-экономическое проектирование - моделирование бизнеса, инвестиционных проектов реального сектора, анализ и оценка эффективности, оптимизация системы управленческих решений.

Широкий спектр web-компетенций для решения задач бизнеса.

Подписывайтесь на мой телеграмм канал - My notes are ECONOMICS +
Повышайте своё качество вместе со мной - что, как и почему в экономике на простом. Микро- и макро аспекты.

А так же - Справочник WEB-разработчика | php+js+seo
Заметки и нативные решения простых локальных задач на PHP, JS. Кое-что про Laravel, WordPress, Vue и SEO.

  Персональная помощь в экономическом проектировании и веб-разработке:

  • Финансово-экономическое моделирование, анализ, учёт, бизнес-планирование
  • Комплексная web-разработка/поддержка проекта в сети (php/js, seo – Laravel, WordPress, Vue, telegram, администрирование, контент, реклама в Яндекс Директ

  telegram или форма обратной связи

Administrator
289
0
Name
E-mail
Rating
Review

Currency Converter
RUB RUB-icon
USD USD-icon
EUR EUR-icon
CNY CNY-icon
BYN BYN-icon
UAH UAH-icon
KZT KZT-icon
ЗАМЕТКИ ЭКОНОМИСТА
SHORT- what is it about
ECONOMIC LITERACY
  Simple online solutions to problems of economics and finance  
I Want To Know Everything. Useful Tips