Call Controller function from webroot file in Cakephp 3
In our example we call AppController function from webroot file. you can call any controller function from webroot file.
To Call Controller function from webroot file in Cakephp create a new file on webroot and paste this code-
Cakephp 3.4
<?php namespace App\Controller; use App\Controller\AppController; if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } require_once(dirname(dirname(__FILE__)).DS.'config'.DS.'bootstrap.php'); require_once(dirname(dirname(__FILE__)).DS.'src'.DS.'Controller'.DS.'AppController.php'); $app = new AppController(); $responseofappfunction = $app->yourAppControllerfunctionName(); ?>
Cakephp 3.8
<?php namespace App\Controller; use App\Controller\AppController; use Cake\Core\Configure; require '../vendor/autoload.php'; use Cake\Routing\Router; if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } require_once(dirname(dirname(__FILE__)).DS.'config'.DS.'bootstrap.php'); require_once(dirname(dirname(__FILE__)).DS.'src'.DS.'Controller'.DS.'AppController.php'); $app = new AppController(); $responseofappfunction = $app->yourAppControllerfunctionName(); print_r( $responseofappfunction ); ?>