A
A
Alexander Andreev2016-12-28 09:23:01
Yii
Alexander Andreev, 2016-12-28 09:23:01

Is there an analogue of the init.php file in 1C Bitrix in Yii?

Tell me, does Yii have some kind of init.php file in 1C Bitrix, into which you can put user-defined functions and call them anywhere in the code? When working with 1C Bitrix, I often use a prepared set of functions (all sorts of wrappers, handlers, parsers, in general, a small toolkit that facilitates development), I wanted to transfer it to a Yii project, but I don’t quite understand where it can be placed and is it possible at all?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Smirnov, 2016-12-28
@maler1988

You can do it like this:
1. Create a helpers directory and create a helper class inside the space, for example: \common\helpers\Paser.php
2. Transfer custom functions as static methods of the Parser.php class and use them in any part of the project by including Your helper class in the use section
If you have such questions, I recommend that you spend more time studying the official documentation.

I
Ilya, 2016-12-28
@rpsv

There are several options:
1. remove everything from a separate component and include it in the necessary projects
2. put the code wherever you want in the 'protected' directory and access the necessary classes using autoload (PSR4 is implemented in yii)

A
Andrey, 2017-01-05
@reaferon

in config file:

'components' => [
....
        'init' => function () {
            return new app\modules\main\models\Init();
        }
....

Accordingly, on the specified path, place the class with all the necessary methods.
And then anywhere in the code:
$ib = Yii::$app->init->GetIBlockElement($id);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question