CakePHP - Class 'AuthComponent' not found in cached view - cakephp

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"

Related

Cache View in CakePHP 3.0

I understand that we can cache an action or view page in CakePHP 2.0. Refer to this link http://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html.
class PostsController extends AppController {
public $helpers = array('Cache');
}
public $cacheAction = array(
'view' => 36000,
'index' => 48000
);
However, it seems that CakePHP 3.0 has removed helper(http://book.cakephp.org/3.0/en/core-libraries/caching.html). Is there any other way in CakePHP 3.0 I can cache the view page. For example, I have a index view/action. And I would like to cache that page. Thanks.
Is there any other way in CakePHP 3.0 I can cache the view page.
Not without developing something yourself. Like for example saving the rendered content to a file in callback for Dispatcher.afterDispatch event and then checking for the file in callback for Dispatcher.beforeDispatch event and returning the cached response.
Better to use you something like Varnish which is more suited for the job.

CakePHP : override BasicAuthenticate.php

I'm trying to override lib/Cake/Controller/Component/Auth/BasicAuthenticate.php,
because I need to change the unauthenticated() method.
So I copied and modified the file to app/Lib/Cake/Controller/Component/Auth/BasicAuthenticate.php (also tried without the 'Cake' folder), but the changes are not taken into account.
My edit works when modifying directly the core file but I'd rather not.
How should I do ?
I'm using Cake 2.5
Check if you really need to override a core class
To me this looks like you are on the wrong track, overriding the class shouldn't be neccesary unless for example you have no controler over where and how the basic authentication adapter is being used (for example in a plugin that doesn't offer configuration).
If you'd really need to overwrite the class, then the path should be
app/Lib/Controller/Component/Auth/BasicAuthenticate.php
and it should work just fine (it does for me, using CakePHP 2.5.6).
http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#overriding-classes-in-cakephp
Use a custom authentication handler instead
If you have control over the adapter configuration, the I'd suggest that you extend the BasicAuthenticate class instead, and only override the unauthenticate() method, and finally make the auth component use the custom adapter.
Something like
app/Controller/Component/Auth/CustomBasicAuthenticate.php
App::uses('BasicAuthenticate', 'Controller/Component/Auth');
class CustomBasicAuthenticate extends BasicAuthenticate {
public function unauthenticated(CakeRequest $request, CakeResponse $response) {
// do something special
}
}
Controller
public $components = array(
'Auth' => array(
'authenticate' => array(
'CustomBasic'
)
)
);
See also the Creating Custom Authentication objects section in the Cookbook.

Helper class sessionHelper could not be found

When trying to run CakePHP based application I'm getting following error:
2014-01-25 11:46:21 Error: [MissingHelperException] Helper class sessionHelper could not be found.
Exception Attributes: array (
'class' => 'sessionHelper',
'plugin' => false,
)
It occurred when I copied CakePHP application to production server. I never had error like this in any of previous developed CakePHP applications.
Just to mention that Session helper is loaded in AppController. PHP version on server is 5.3.10.
Try to include SessionHelper instead of sessionHelper
public $helpers = array('Session');
If the production server is on unix, this is important.
Include SessionHelper as cornelb said. And be careful when calling Session helper manually, just call it with capital 'S':
$this->Session->read('Auth.User');

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

Resources