Y
Y
Yuri Voronin2018-12-03 15:28:41
1C-Bitrix
Yuri Voronin, 2018-12-03 15:28:41

How to execute php file from php function?

Hello
There is a file https: //test.loc/sales/save.php
When we run it in the browser, everything works fine. There are certain manipulations with the database (adding data)

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");

$APPLICATION->IncludeComponent(
    "bitrix:get.sales",
    "save",
    Array( ),
    false
);

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");

I have a function that fires under a certain condition. And I need that when this function is called, https: //test.loc/sales/save.php is executed
I tried
function refreshDiscountSales ($primary, $fields) {
    include($_SERVER["DOCUMENT_ROOT"]."/sales/save.php");
}

After execution, the database is empty, i.e. nothing added. And it shouldn't be. Maybe it should be done differently?
PS cms 1c bitrix

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Koryukov, 2018-12-03
@MadridianFox

For good reason, you need to take the save code out of the component, so that it is not tied to an http request, but accepts data as parameters. And this code must be called from the component and from your function.
Well, as a matter of fact, you don't need to include a file, but make an http request to this page. The new versions of Bitrix have such a thing as HttpClient. At the very least, you can always use curl for this task.

J
Jupiter Max, 2018-12-03
@vardoLP

well, now you just have a function, you need to call it after some actions
refreshDiscountSales();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question