CakePHP Sending Files - cakephp

I am trying to render images/pdfs that exist outside of my webroot. So this is what I'm doing in my controller to Send the File - as described here. But I'm getting a Fatal Error. Any ideas why and how to fix this? I'm running CakePHP 2.4.5.
$this->autoRender = false;
$path = '/path/to/valid/file.pdf';
$this->response->file($path);
return $this->response;
Fatal error: Call to undefined method Folder::slashTerm()
Stack trace:
{main}() /Path/To/My/htdocs/mysite/app/webroot/index.php:0
Dispatcher->dispatch() /Path/To/My/htdocs/mysite/app/webroot/index.php:96
Dispatcher->_invoke() /Path/To/My/htdocs/mysite/lib/Cake/Routing/Dispatcher.php:160
Controller->invokeAction() /Path/To/My/htdocs/mysite/lib/Cake/Routing/Dispatcher.php:185
ReflectionMethod->invokeArgs() /Path/To/My/htdocs/mysite/lib/Cake/Controller/Controller.php:490
PagesController->load_media() /Path/To/My/htdocs/mysite/lib/Cake/Controller/Controller.php:490
CakeResponse->file() /Path/To/My/htdocs/mysite/app/Controller/PagesController.php:227
File->__construct() /Path/To/My/htdocs/mysite/lib/Cake/Network/CakeResponse.php:1265
File->pwd() /Path/To/My/htdocs/mysite/lib/Cake/Utility/File.php:91

Problem solved. I had a Plugin that had a class Folder that was taking this over.

Related

CakePHP 2 MissingControllerException in error.log => show accessed url

Is it possible to create/extend a CakePHP Exception handler which shows the url the user tried to access which throws the exception?
Usually when I look into my error.log file I see something like this:
2012-08-01 13:39:20 Error: [MissingControllerException] Controller class UserController could not be found.
#0 /www/htdocs/w0081e0e/app/webroot/index.php(104): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
I have a working UsersController but I'm not sure which url the user tried to access which in return throw this error. It would help me to see the url in the error.log file. Is that possible? Would I have to create/extend an exception handling file?
Update:
Instead of writing my own ExceptionHandler I just updated the "handleException" function in "lib/Cake/Error/ErrorHandler.php":
if (!empty($config['log'])) {
$message = sprintf("[%s] %s\n%s",
get_class($exception),
$exception->getMessage(),
$exception->getTraceAsString().' - http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n"
);
CakeLog::write(LOG_ERR, $message);
}
I know that this is overwritten once I update my CakePHP Version but its a quick fix that works really fine for my situation.
You can write your own exception handlers. It's pretty well documented at http://book.cakephp.org/2.0/en/development/exceptions.html#create-your-own-exception-handler-with-exception-handler
Anyway the URL seems to be like http://something/user/something. The error says UserController could not be found, which is true as you only have a UsersController (plural). If you just want to avoid this error it might be enough to find the file which creates a /user/ URL.

node_load($nid) gives me a fatal error in Drupal 7

Pretty new to drupal 7 and a lot has changed. How can I simply load a node and print it out? I am using the following but the function node_load gives me: PHP Fatal error: Call to undefined function node_load()
$node = node_load(15);
echo '<pre>' . print_r($node,1) . '</pre>';
it sounds like it cant find the function node_load - which i can imagine only happening if you were trying to do this outside of the drupal framework? e.g. on a PHP page youve simply added into the webspace?
contents of file:
<?php
node_load(1);
make sure you have the node_load inside a drupal module you have created, and when its responding to a hook ( e.g. hook_view )
sites > all > modules > yourmodule
yourmodule.module
yourmodule_view($node, $view_mode){
node_load(1);
}

cakephp app error problem

I have the following function in my app_controller:
function beforeFilter() {
$this->set('lastThreePosts', $this->Blog->find_latest_posts());
}
I then use the variable 'lastThreePosts' that I have set in my layout. This works fine apart from on my 404 page where I get the following error:
Notice (8): Undefined index: lastThreePosts [APP\views\layouts\default.ctp, line 29]
I have made my own 404 page by created the file error404.ctp in my /views/errors/ directory.
So it seems when theres a 404 error the code in the controller doesn't get executed. Does anyone know how I can make it work?
Thanks
Phew! I found the answer here:
http://www.bradezone.com/2009/05/21/cakephp-beforefilter-and-the-error-error/

I am getting error : Fatal error: Call to undefined method Debugger::checkSessionKey() in F:\xampp\htdocs\cakecms\views\pages\home.ctp on line 3

Fatal error: Call to undefined method Debugger::checkSessionKey() in F:\xampp\htdocs\cakecms\views\pages\home.ctp on line 3
in cake php .
Are you trying to call $this->Session from your home.ctp? I don't think $this->Session is available to views.
If you show your code for home.ctp we could better see what is going on.

CakePHP "Warning: Cache not configured properly"

I am using CakePHP and getting the following error
Warning: Cache not configured properly. Please check Cache::config(); in APP/config/core.php in D:\PHP-SERVER\cheesecake\cake\libs\configure.php on line 663
Notice: Undefined variable: Route in D:\PHP-SERVER\cheesecake\app\config\routes.php on line 38
Fatal error: Call to a member function connect() on a non-object in D:\PHP-SERVER\cheesecake\app\config\routes.php on line 38
Any problem in the settings?
Which CakePHP version are you using?
The fatal error looks like a typo. Open the file D:\PHP-SERVER\cheesecake\app\config\routes.php and check what there is written on line 38. It looks like there is a letter missing.
It should be something along the lines of
Router::connect(...[whatever your route settings are]...);
and I guess in your file it says (note the missing r in Router)
Route::connect(...);
Did you do what the other error message said? Check the Cache::config call in app/config/core.php. You seem to have not properly set your cache configuration.
The default call looks like
Cache::config('default', array('engine' => 'File'));
If you changed that post the code-piece to figure out if something is wrong..

Resources