Roots Discourse

Define a path in a Class

hello everyone,

I am creating a light profanity checker in a project.
This checker have a set of dictionaries in a folder /dictionaries/

I have created a class which loads the dictionaries and does some stuffs.

How can i declare the path:

    ...
    namespace App;
    define("DICT_PATH", @asset("dictionaries/")); //<-- HERE
    ...

considering I have put the /folder in the /assets/ one?

@asset is a directive which will only work in Blade templates. See: Use function in app.php to build url for image html - understanding scope/templates

As for how you should load that dictionary it depends on what sort of thing it is. An “asset” is generally something that runs through the build process and is compiled, transpiled, compressed, etc. More specifically though, and asset is a file that needs a publicly accessible url. An image needs that; a file loaded by a PHP script does not. WordPress provides the get_stylesheet_directory() function to return the path of files in your theme.

so you mean it is not formally correct to create a folder there?
I would go this way in sake of clean installation and order… :confused:

shall I then load the file by using get_stylesheet_directory() from the /asset/ folder?

This topic was automatically closed after 42 days. New replies are no longer allowed.