ControllerFile not found error in cakephp - 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 controller 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.

Related

CakePHP - Class 'AuthComponent' not found in cached view

I'm using CakePHP 2.3. and I'm trying to cache my home page view. But After caching
it to home.php, I can't load cached view because of error:
Error: Class 'AuthComponent' not found
File: C:\wamp\www\project\trunk\app\tmp\cache\views\home.php
Line: 87
I use AuthComponent for realizing if user is logged in or not. Without caching Everything works.
Controller code:
public $helpers = array('Cache');
public $cacheAction = array(
'home' => '60 minutes',
);
Thanks
App::uses() your Auth component in your bootstrap would help:
App::uses('AuthComponent', 'Controller/Component');
This way Cake knows where to load the class from if its needed (even in cache mode).
That would be this line in the file \config\bootstrap.php
App::uses('AuthComponent', 'Controller/Component');
Note that I tried this in Cake 4.1.5 but it tlls me "Class 'AuthComponent' not found"

Cakephp can't locate core helper: JqueryEngineHelper.php when on server

When I run my app on my locale machine it works fine, but when I run it on my sever using cpanel, everything works fine expect when I use js helper using jquery library the following error occurs
Error: jqueryEngineHelper could not be found.
Error: Create the class jqueryEngineHelper below in file:
app/View/Helper/jqueryEngineHelper.php
<?php
class jqueryEngineHelper extends AppHelper {
}
Nb: all the files exists.
It's incorrectly looking for "jqueryEngineHelper" instead of "JqueryEngineHelper" which most likely means you didn't use correct casing when specifying the helper in controller. Make sure you have public $helpers = array('Js' => array('Jquery')); with capital "J" for "Jquery" and not "jquery"
Try with App::uses() to load the helper.
http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#loading-classes
Example from CakePHP documentation:
App::uses('HtmlHelper', 'View/Helper');
You try:
App::uses('jqueryEngineHelper', 'View/Helper');
EDIT:
Try putting that in your AppController.php at your starting lines in your code.

cakephp REST problem

** SOLUTION **
I am using cakephp 1.3. I did not have to add any routes. All i did is after adding the action to the controller, I went to the url
/controller/action/id
in my case it was
/test/bravo/123
and that did the trick
** End **
I am using cakephp 1.3 and I am trying to add webservice. I heard its very easy to add restful. What I want to do is to have one of the actions in my controller provoked and log into a logfile as a success. Lets say
function bravo(){ $this->log("success", "Testlog");
So far I went through documentation and added the following to my routes.php
Router::mapResources('tests');
Router::parseExtensions();
then in test controller I have this
<?php
class TestsController extends AppController {
var $name = 'Tests';
var $components = array('RequestHandler');
.....
.....
function bravo(){
$this->log("success", "Testlog");
}
?>
Now when I go to
/tests.bravo
, its not logging the success in the log file. What am I doing wrong. Thanks

Cakephp html2pdf auth problem

i am new with cake but i´ve somehow managed to get through so far. After i´ve figured out that html2pdf is a convienient way to produce pdf documents out of Cakephp, i´ve installed html2ps/pdf and after some minor problems it worked. So now i am coming now to the point that if i don´t modify my controllers beforeRender function like:
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('download','view');
}
i just see my loginpage in the pdf i´ve created. Setting within my beforeRender function the $this->Auth->allow value opens obviously erveryone the way to get a perfect pdf without being authorized. The whole controller looks like this:
<?php
class DashboardController extends AppController {
var $name = 'Dashboard';
var $uses = array('Aircrafts','Trainingplans',
'Fstds','Flights','Properties','Person');
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('download','view');
}
function view() {
/* set layout for print */
$this->layout = 'pdf';
/* change layout for browser */
if> (!isset($this->params['named']['print']))
$this->layout = 'dashboard';
/* aircrafts */
$this->Aircrafts->recursive = 0;
$aircrafts =$this->Aircrafts->find('all');
$this->set('aircrafts',$aircrafts);
.... and so on....
$this->set('person_properties',$person_properties);
}
function download($id = null) {
$download_link = 'dashboard/view/print:1';
// Include Component
App::import('Component', 'Pdf');
// Make instance
$Pdf = new PdfComponent();
// Invoice name (output name)
$Pdf->filename = 'dashboard-' . date("M");
// You can use download or browser here
$Pdf->output = 'download';
$Pdf->init();
// Render the view
$Pdf->process(Router::url('/', true) . $download_link);
$this->render(false);
}
}
?>
So in my opinion the $Pdf->process call get´s the data by calling more or less the view, but this process is not logged in, or in other words not authorized to get the data i want to render into the pdf. So the question is now how to get it done by not opening my application to everyone.
Best regards, cdjw
Edit:
You could do something like this:
if($this->Session->check('Auth.User')) {
// do your stuff
} else {
// do something else
}
You could check for 2 things before rendering /view:
a valid session (a user is logged in)
a valid security token that you pass from your download action as a named parameter
For the security token, just make up a long random string.
As the PDF is rendered on the same server, the token will never be known in the open and provide sufficient security.
Hope this is a working idea for you.
I had this similar issue, and this is how I handled it...
I first noticed that the process call of the PdfComponent was doing a request from the same server, so I tricked CakePHP on allowing the view only for requests being made from the server itself.. like this:
public function beforeFilter() {
if ($this->request->params['action']=='view'&&$_SERVER['SERVER_ADDR']==$_SERVER['REMOTE_ADDR']) { // for PDF access
$this->Auth->allow('view');
}
}
You should put
$this->Auth->allow('download','view');
inside AppController. rather than place where are you using now.
function beforeFilter() {
$this->Auth->allow('download','view');
....
}

cakePHP : x_with in action / function causes errors... repeatable?

In a controller, make a dummy action, name it like stackoverflow_with_something()//the WITH part is important
Create the view stackoverflow_with_something
Load up the page in a browser. Get a 'missing view error'
Take out the _with, try again. No error.
I havent seen any documentation on this, whats the deal?
short version : Why does xxxxx_with_xxxxx crash cakePHP, but xxxxx_xxxxx dosent?
No problems here, tried with the following:
/app/controllers/foos_controller.php:
<?php
class FoosController extends AppController {
var $uses = null;
function bar_with_yadda() {
}
}
?>
/app/views/foos/bar_with_yadda.ctp:
Hello
requesting /foos/bar_with_yadda returns no error.

Resources