How do I access the modx api in a php file that is in a folder called livesearch?

I have a folder called live search which I’m using to store all of my php files for an Ajax search system. I need to require_once '/connectors/config.core.php'; require_once MODX_CORE_PATH '/model/modx/modx.class.php'; but it gives me an error. How do I make this work.

Assuming your folder is located in the root, just “go one directory up” with dirname:

require_once dirname(__DIR__) . '/connectors/config.core.php'

If adjusting a require clause to match your filesystem is out of your skill set, I would however urge caution building custom search systems. While MODX tries to protect you, whenever you write custom PHP without understanding the very basics, it is easy to introduce security vulnerabilities.

Ready-made extras like AjaxSearch do exist for MODX that are likely more secure and well tested than building something like it yourself.

1 Like

it is located in the www directory. Sorry for not clarifying. I just haven’t messed with php modules very much. All of the stuff I have had to do so far hasn’t required packages.

The live search already works I just need to implement it into modx.