In concrete5 how do you create a stand alone script that uses concrete5 built in models

StackOverflow https://stackoverflow.com/questions/16718875

  •  30-05-2022
  •  | 
  •  

Question

I need to create a script that reads data on a concrete5 site. I do not want to create a new db connection or create a database connection outside of the concrete5 api environment. Is it possible to include some scripts from the concrete5 cms and somehow have access to the models so that I can access the data?

Was it helpful?

Solution

There are two ways.

The simplest is via the web server (including a CURL request from the command line) to access a tools file. Check out the [root]/concrete/tools directory for examples. You'd put it in [root]/tools. Tools are much simpler than a single page, but get all the models loaded, etc.

Otherwise, you can run from the command line. See http://www.concrete5.org/community/forums/documentation_efforts/how-to-running-concrete5-from-php-command-line/ . Same deal applies -- you'll get the basic models automatically, and you can use Loader::whatever() like normal.

OTHER TIPS

Starting from concrete5 version 8, you can execute PHP scripts in a terminal (bash, Windows command line, ...) using the c5:exec CLI command.

For instance, if your script is named exec-me.php, you can execute it with the following command:

concrete/bin/concrete5 c5:exec exec-me.php

(Under Windows, simply replace the / with \)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top