Answer the question
In order to leave comments, you need to log in
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
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.
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)
in config file:
'components' => [
....
'init' => function () {
return new app\modules\main\models\Init();
}
....
$ib = Yii::$app->init->GetIBlockElement($id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question