Skip to content

Instantly share code, notes, and snippets.

@hh-com
Created December 13, 2018 19:39
Show Gist options
  • Save hh-com/ddbea48d83d52f323c2392a40c8c930a to your computer and use it in GitHub Desktop.
Save hh-com/ddbea48d83d52f323c2392a40c8c930a to your computer and use it in GitHub Desktop.
Boilerplate: Contao4- Run Singlefile without Module (by Cron)
<?php
/**
**/
define('TL_MODE', 'FE');
define('BYPASS_TOKEN_CHECK', true);
/*Cache-Control:*/
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Pragma: no-cache"); //HTTP 1.0
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
// Include the Contao initialization script
# PUT YOUR EXTERNAL SCRIPT IN /web/system/modules/modulename/
# to prevent the message Your script is not compatible with Contao 4. define this Tl_SCRIPT
define('TL_SCRIPT', 'system/modules/modulename/index.php');
// ++++++ !!!FIND PATH!!! ++++++
$dir = __DIR__;
while ($dir != '.' && $dir != '/' && !is_file($dir . '/system/initialize.php'))
{
$dir = dirname($dir);
}
if (!is_file($dir . '/system/initialize.php'))
{
throw new \ErrorException('Could not find initialize.php!',2,1,basename(__FILE__),__LINE__);
}
require($dir . '/system/initialize.php');
class runWithoutModule extends \Controller
{
/**
* Must be defined cause parent is protected.
*/
public function __construct() {}
/*
* Run this script
*/
public function run()
{
echo "do something";
}
}
$runReminder = new runWithoutModule();
$runReminder->run();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-xs-6">
<h1>Output for something</h1>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment