ControllerFile not found error in cakephp
HI! I'm trying to create the web service in the cakePhp. I'm new to cakePhp and only recently start working on it. I found a useful tutorial at http://www.littlehart.net/atthekeyboard/2007/03/13/how-easy-are-web-services-in-cakephp-12-really-easy/ I created both the controller and index.ctp files as described in the tutorial. But when I typed the url (http://localhost:81/cakephp/foo) of the controller to run the file, I got the following error:
// controllers/recipes_controller.php
/**
* Test c开发者_高级运维ontroller for built-in web services in Cake 1.2.x.x
*
* @author Chris Hartjes
*
*/
class FooController extends AppController {
var $components = array('RequestHandler');
var $uses = '';
var $helpers = array('Text', 'Xml');
function index() {
$message = 'Testing';
$this->set('message', $message);
$this->RequestHandler->respondAs('xml');
$this->viewPath .= '/xml';
$this->layoutPath = 'xml';
}
}
CakePHP: the rapid development php framework
Missing Controller
Error: FooController could not be found.
Error: Create the class FooController below in file: app\controllers\foo_controller.php
Strange thing is that (everyone can see) that controller text is loaded in the error page, but error shows that controller file is not found. I also tried to follow the tutorial on book.cakephp.org/view/477/The-Simple-Setup. But same error also occured here. Anyone can help? By the way I also changed the text of routes.php to work it with web webservices. Thanks
The fact that the contents of your FooController
file is being output in the browser indicates that the PHP is not being executed.
You need to ensure that the definition for your FooController
class is enclosed in <?php
and ?>
tags, like this:
// controllers/recipes_controller.php
/**
* Test controller for built-in web services in Cake 1.2.x.x
*
* @author Chris Hartjes
*
*/
<?php
class FooController extends AppController {
var $components = array('RequestHandler');
var $uses = '';
var $helpers = array('Text', 'Xml');
function index() {
$message = 'Testing';
$this->set('message', $message);
$this->RequestHandler->respondAs('xml');
$this->viewPath .= '/xml';
$this->layoutPath = 'xml';
}
}
?>
You have entered the URL http://localhost:81/cakephp/foo
. Cake correctly interprets this to mean you are looking for the index
action on the FooController
. The error doesn't mean it has found the file, just that it has worked out what to look for but hasn't found it where it expects it to be.
The line: Error: Create the class FooController below in file: app\controllers\foo_controller.php
tells you what should be there (and what, as a minimum, it should look like). Check that you have named the file correctly and that it located where the error says it should be.
精彩评论