Page 1 of 1

Independent custom scripts

Posted: Mon Apr 15, 2024 1:05 am
by sclg

I have a few 'helper' programs in the PHPM project folder which need to use Composer packages. These programs effect the database but, apart from being in the PHPM menu, they are otherwise independent of PHPM.

Because I want to use Composer packages, I add the line
require 'vendor/autoload.php';
to my programs

... but when I do this, everything fails with
Error: Undefined constant "PHPMaker2024\cpbartabs2024\PROJECT_CHARSET" in D:\wwwroot\cpbartabs\src\config.php on line 158

I assume autoload.php is loading config.php which is creating this error.
I don't know why PROJECT_CHARSET is undefined. 'Charset' is set to utf-8 on HTML-General.

Is there a way to fix this or is it just impossible for programs outside PHPM to utilise Composer packages like this?
Thanks


Re: PROJECT_CHARSET error

Posted: Mon Apr 15, 2024 8:46 am
by mobhar

Did you mean you use Custom Files for your "helper" above?


Re: Independent custom scripts

Posted: Mon Apr 15, 2024 10:02 am
by arbei

sclg wrote:

I assume autoload.php is loading config.php which is creating this error.

No, autoload.php is only for composer packages, you need to include other required files yourself, you may refer to the index.php.


Re: PROJECT_CHARSET error

Posted: Mon Apr 15, 2024 3:49 pm
by sclg

mobhar wrote:

Did you mean you use Custom Files for your "helper" above?

No - it's not a 'Custom File'


Re: Independent custom scripts

Posted: Mon Apr 15, 2024 3:51 pm
by sclg

arbei wrote:

No, autoload.php is only for composer packages, you need to include other required files yourself, you may refer to the index.php.

So why is config.php being loaded? I'm not including ANY files except with "require 'vendor/autoload.php'; "


Re: Independent custom scripts

Posted: Mon Apr 15, 2024 6:29 pm
by arbei

You included it indirectly, possibly by some other include files in your script, but you did not include the constants.php, hence the error.

You may post your code for discussion.