Posted by Doug Hays on the 11th of January, 2010 at 11:13 pm under CakePHP.    This post has no comments.

In order to call CakePHP from non-CakePHP code, we will copy index.php from /app/webroot and put it into our non-CakePHP codebase as cakephp.php.

Then, we’ll create a function requestCakePHP that requires the cakephp.php file:

function requestCakePHP($url)


// Set the url parameter for cakephp
$_GET['url'] = $url;

require_once 'cakephp.php';

// Fire up CakePHP and buffer results
$Dispatcher= new Dispatcher ();

return ob_get_clean();


Then, whenever we need to call for some Cake, we just call requestCake with the URL minus the hostname:

echo requestCakePHP("/webpages/view/2");

In the example above, I have a webpages controller, a view action and am viewing webpage #2.