Disabling E_STRICT errors in CakePHP Beanstalk - cakephp

After I've upgraded PHP to 5.4, PHP complains about E_STRICT.
My VPS has Ubuntu 12.04 installed. It has a lot of .ini-files, and I've changed all error_reporting to:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
I've also restarted the Apache-webserver.
Phpinfo tells me that ~E_STRICT not is blocked (error_reporting => 22527 => 22527)
I know: the best option is to change de code. All & references has been removed.
In the following list, the log:
Strict (2048): Declaration of BeanstalkdSource::create() should be compatible with DataSource::create(Model $model, $fields = NULL, $values = NULL) [APP/Plugin/Queue/Model/Datasource/BeanstalkdSource.php, line 396]
Strict (2048): Declaration of BeanstalkdSource::read() should be compatible with DataSource::read(Model $model, $queryData = Array, $recursive = NULL) [APP/Plugin/Queue/Model/Datasource/BeanstalkdSource.php, line 396]
Strict (2048): Declaration of BeanstalkdSource::update() should be compatible with DataSource::update(Model $model, $fields = NULL, $values = NULL, $conditions = NULL) [APP/Plugin/Queue/Model/Datasource/BeanstalkdSource.php, line 396]
Strict (2048): Declaration of BeanstalkdSource::delete() should be compatible with DataSource::delete(Model $model, $id = NULL) [APP/Plugin/Queue/Model/Datasource/BeanstalkdSource.php, line 396]
Strict (2048): Only variables should be passed by reference [APP/Plugin/Queue/Model/Datasource/BeanstalkdSource.php, line 382]
DETAILS:
Strict (2048): Declaration of BeanstalkdSource::create() should be compatible with DataSource::create(Model $model, $fields = NULL, $values = NULL) [APP/Plugin/Queue/Model/Datasource/BeanstalkdSource.php, line 396]
Code Context
if (file_exists($file)) {self::_map($file, $className, $plugin); return include $file;
App::load() - CORE/Cake/Core/App.php, line 563
App::load() - CORE/Cake/Core/App.php, line 563
spl_autoload_call - [internal], line ??
class_exists - [internal], line ??
ConnectionManager::loadDataSource() - CORE/Cake/Model/ConnectionManager.php, line 179
ConnectionManager::getDataSource() - CORE/Cake/Model/ConnectionManager.php, line 96
Model::getDataSource() - CORE/Cake/Model/Model.php, line 3245
Model::__call() - CORE/Cake/Model/Model.php, line 800
Job::put() - APP/Event/ScenarioModifiedListener.php, line 75
ScenarioModifiedListener::StartPdfScenarioJob() - APP/Event/ScenarioModifiedListener.php, line 75
ScenarioModifiedListener::StartPdfJob() - APP/Event/ScenarioModifiedListener.php, line 58
call_user_func - [internal], line ??
CakeEventManager::dispatch() - CORE/Cake/Event/CakeEventManager.php, line 248
ScenarioModifiedBehavior::afterSave() - APP/Model/Behavior/ScenarioModifiedBehavior.php, line 84
ObjectCollection::trigger() - CORE/Cake/Utility/ObjectCollection.php, line 132
call_user_func - [internal], line ??
CakeEventManager::dispatch() - CORE/Cake/Event/CakeEventManager.php, line 248

Related

Form data is hashed in CakeRequest after upgrade to cakephp2.x

I just recently performed an upgrade from cakephp 1.3 to 2.06. However when I attempt to access form data in my controller, the data is hashed like so:
2015-10-15 08:43:57 Error: CakeRequest Object
(
[params] => Array
(
[plugin] =>
[controller] => custom_users
[action] => ajax_login
[named] => Array
(
)
[pass] => Array
(
)
[isAjax] => 1
)
[data] => e1fe8b4c1724c30148e306708f27b30909f23d45
I checked that the form is correctly formed on the front end.
The documentation indicates that I should be able to access my data this way, but for some reason this behaviour is happening in stead. Any ideas?
I've added the trace I get when I try and submit the form:
Notice: Array to string conversion in /var/www/html/academy/lib/Cake/Utility/Security.php on line 92
Notice: Undefined offset: 1 in /var/www/html/academy/lib/Cake/Network/CakeResponse.php on line 456
Warning: Illegal string offset 'CustomUser' in /var/www/html/academy/app/Controller/CustomUsersController.php on line 569
Warning: Illegal string offset 'username' in /var/www/html/academy/app/Controller/CustomUsersController.php on line 569
Warning: Illegal string offset 'CustomUser' in /var/www/html/academy/app/Controller/CustomUsersController.php on line 570
Warning: Illegal string offset 'password' in /var/www/html/academy/app/Controller/CustomUsersController.php on line 570
Warning: implode(): Argument must be an array in /var/www/html/academy/lib/Cake/Utility/Security.php on line 92
Fatal error: Call to undefined method CustomAuthComponent::getModel() in /var/www/html/academy/app/Controller/Component/CustomAuthComponent.php on line 242

CakePHP file download corrupted

I have a site where users can upload images and then download them. I have moved my project on a live web host but the problem is that when I try to download the file I just uploaded, it downloads it but cant open it afterwards, it says it is corrupted... I had no problems in local though.
heres my download action:
public function getfile($accesskey) {
$this->autoRender = false;
if ($accesskey != null) {
$data = $this->getfileinfo($accesskey);
if (!empty($data)) {
$this->response->file(WWW_ROOT.$data['Document']['dlpath'], array('download' => true, $data['Document']['name']));
return $this->response;
} else {
$this->redirect(array('controller' => 'documents', 'action' => 'upload'));
}
} else {
$this->redirect(array('controller' => 'documents', 'action' => 'upload'));
}
}
$data['Document']['dlpath'] contains the following:
/home/vol2_2/byethost17.com/b17_15357734/htdocs/app/webroot/uploads/2014/09/26/filekey/imagename.extension
this is the first time i'm doing this so i might have made a mistake.. the path is wrong or something i'm confused
EDIT: It seems that the error i was getting was much deeper than it seemed. I opened the corruted file in a text editor and saw some error concerning set_time_limit() and php safe mode...
here's the error:
Warning (2) : set_time_limit() has been disabled for security reasons [ CORE/Cake/Network/CakeResponse.php , line 1458 ] Code Context
set_time_limit - [internal], line ??
CakeResponse::_sendFile() - CORE/Cake/Network/CakeResponse.php, line 1458
CakeResponse::send() - CORE/Cake/Network/CakeResponse.php, line 429
MediaView::render() - CORE/Cake/View/MediaView.php, line 96
Controller::render() - CORE/Cake/Controller/Controller.php, line 954
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 198
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 165
[main] - APP/webroot/index.php, line 108

CakePHP PaginationRecallComponent, Strict (2048): Declaration of PaginationRecallComponent::initialize()

I have tried to insert PaginationRecallComponent (http://bakery.cakephp.org/articles/Zaphod/2012/03/27/paginationrecall_for_cakephp_2_x), in
App -> Controller -> Component -> PaginationRecallComponent.php
UserController:
public $components = array('PaginationRecall');
Why I received the following error:
Strict (2048): Declaration of PaginationRecallComponent::initialize() should be compatible with Component::initialize(Controller $controller) [APP/Controller/Component/PaginationRecallComponent.php, line 46]
Code Context
App::load() - CORE/Cake/Core/App.php, line 567
App::load() - CORE/Cake/Core/App.php, line 567
spl_autoload_call - [internal], line ??
class_exists - [internal], line ??
ComponentCollection::load() - CORE/Cake/Controller/ComponentCollection.php, line 110
ComponentCollection::init() - CORE/Cake/Controller/ComponentCollection.php, line 53
Controller::constructClasses() - CORE/Cake/Controller/Controller.php, line 652
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 183
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 162
[main] - APP/webroot/index.php, line 97
CakePHP 2.4.2
You get this error because the signature of the initialize method in the PaginationRecallComponent class is different from the one in its parent class.
If you look at the code you will see that in Cake/Controller/Component.php the signature is:
public function initialize(Controller $controller)
whereas in the PaginationRecallComponent it is:
function initialize(&$controller)
In the first case the $controller parameter must be an instance of Controller, whereas in the second case there is no such constraint. To get rid of the error you simply have to add this constraint to the signature of the initialize method of the PaginationRecallComponent.

CakePHP, using component Cookie in AppController

I can't seem to use a component in AppController?
class AppController extends Controller {
var $helpers = array('Facebook', 'Session', 'Menu', 'Html', 'Form'); // Facebook is a custom helper.
var $components = array('Cookie');
function beforeFilter ( )
{
$this->Cookie->name = '[removed]';
$this->Cookie->path = '/cake/';
$this->Cookie->domain = 'localhost';
$this->Cookie->key = '[removed]';
$this->_initUser();
}
function _initUser ( ) // Using this for a cleaner default.ctp
{
#Controller::loadModel('User');
// DEFINE facebook variables globally
$GLOBALS['APP_ID'] = '[removed]';
$GLOBALS['APP_SECRET'] = '[removed]';
$GLOBALS['REDIRECT_URI'] = 'http://localhost/cake';
// Check if logged in with Facebook.
if($this->Cookie->read('User') == null && isset($_GET['code'])) // Line 57.
.
.
.
Here is the error PHP is throwing up:
Notice (8): Undefined property: View::$Cookie [APP\app_controller.php, line 57]Code
// Check if logged in with Facebook.
if($this->Cookie->read('User') == null && isset($_GET['code'])) AppController::_initUser() - APP\app_controller.php, line 57
include - APP\views\layouts\default.ctp, line 47
View::_render() - CORE\cake\libs\view\view.php, line 731
View::renderLayout() - CORE\cake\libs\view\view.php, line 489
View::render() - CORE\cake\libs\view\view.php, line 435
Controller::render() - APP\controller.php, line 909
PagesController::display() - APP\controllers\pages_controller.php, line 83
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - APP\webroot\index.php, line 83
Fatal error: Call to a member function read() on a non-object in C:\xampp\htdocs\cake\app\app_controller.php on line 57
Please help, I have no idea about what I should do!
Aha! I fixed it finally. The problem was that my Facebook component read class FacebookHelper accidentally.
I fixed this issue and then it continued to execute the rest of AppController normally and it worked.
Never going to code post-midnight again.

Instance for File is not working in cakephp

i am getting the error as
Array to string conversion [CORE/cake/libs/file.php, line 96]
$path = array(
"name" => "23_50_11[1].gif",
"type" => "image/gif",
"tmp_name" => "/tmp/phpbBWxAT",
"error" => 0,
"size" => 25230
)
$create = false
$mode = 493
dirname - [internal], line ??
File::__construct() - CORE/cake/libs/file.php, line 96
FormsController::add() - APP/controllers/forms_controller.php, line 528
Object::dispatchMethod() - CORE/cake/libs/object.php, line 117
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 245
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 211
require - APP/webroot/index.php, line 88
[main] - CORE/index.php, line 61
Notice (8): Array to string conversion [CORE/cake/libs/file.php, line 97]
$path = array(
"name" => "23_50_11[1].gif",
"type" => "image/gif",
"tmp_name" => "/tmp/phpbBWxAT",
"error" => 0,
"size" => 25230
)
$create = false
$mode = 493
is_dir - [internal], line ??
File::__construct() - CORE/cake/libs/file.php, line 97
FormsController::add() - APP/controllers/forms_controller.php, line 528
Object::dispatchMethod() - CORE/cake/libs/object.php, line 117
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 245
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 211
require - APP/webroot/index.php, line 88
[main] - CORE/index.php, line 61
Warning (2): basename() expects parameter 1 to be string, array given [CORE/cake/libs/file.php, line 98]
The code that i have used is,
<h1>Form Fill</h1>
<?=$form->create('Form',array('type'=>'file'));?>
<?=$form->input('date',array('label'=>'Publication Date '));?>
<?=$form->input('headline');?>
<?=$form->input('content');?>
<?=$form->input('image',array('type'=>'file'));?>
<?=$form->end('Submit');?>
in the Formscontroller
function add($formid)
{
echo "Imaage ".$this->data['Form']['image'];// shows me the Imaage Array
if ($this->data['Form']['image']) {
$file = new File($this->data['Form']['image']);// this is not working
//$ext = $file->ext();
//echo "Extension ".$ext;
echo "Fiel ".$file;
$date = $this->data['Form']['date'];
$filename = $date['year'].'-'.$date['month'].'-'.$date['day'].'-form-image.'.'gif';
$data = $file->read();
echo "Data ".$data;
$file->close();
$file = new File(WWW_ROOT.'/img/'.$filename,true);
$file->write($data);
$file->close();
}
}
Instance for File is not working?? Please help me . actually i m trying to upload the image FIle and i m using Ubuntu linux machine ..
To recap:
$this->data['Form']['image']; // shows me the Imaage Array
$file = new File($this->data['Form']['image']); // this is not working
Error: Array to string conversion
The problem:
new File() expects a string as argument, but you're giving it an array.
Solution:
Supply a string as argument for new File(), preferably the path of the file:
$file = new File($this->data['Form']['image']['tmp_name']);
To be a little more detailed and help you fix these kinds of problems yourself next time (hopefully), it's not actually File that expects a string argument. If you look at the trace again:
dirname - [internal], line ??
File::__construct() - CORE/cake/libs/file.php, line 96
FormsController::add() - APP/controllers/forms_controller.php, line 528
...
This says the problem actually occurred in dirname, which is a PHP internal function. It was called on line 96 in File::__construct, which in turn was called from FormsController::add etc. pp.
Since PHP is a dynamic language it doesn't usually crap out completely when you supply arguments of the wrong type. Rather it'll try to make the best out of it and actually try to convert an array to a string, and just notify you that it did so with Notice (8): Array to string conversion. Since the result of an Array -> String conversion is literally the string "Array", your program will usually crap out later, since now you're trying to do things like is_dir("Array"), which is nonsense.
As you can see the program actually struggles on, with quite a few notices, and basename() on line 98 even complaining a little harder with a Warning:
94: function __construct($path, $create = false, $mode = 0755) {
95: parent::__construct();
96: $this->Folder =& new Folder(dirname($path), $create, $mode);
97: if (!is_dir($path)) {
98: $this->name = basename($path);
Warning (2): basename() expects parameter 1 to be string, array given [CORE/cake/libs/file.php, line 98]
Now, it would be good style for File to check if the parameter actually is a string or not and fail gracefully, but it doesn't bother. Because as a developer you should read the documentation to see what the function expects. If it's not on the website, look directly in the file /cake/libs/file.php:
/**
* Constructor
*
* #param string $path Path to file
* #param boolean $create Create file if it does not exist (if true)
* #param integer $mode Mode to apply to the folder holding the file
* #access private
*/
function __construct($path, $create = false, $mode = 0755) {
...

Resources