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

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.

Related

Django/pyodbc error: not enough arguments for format string

I have a Dictionary model defined in Django (1.6.5). One method (called get_topentities) returns the top names in my dictionary (entity names are defined by Entity model):
def get_topentities(self,n):
entities = self.entity_set.select_related().filter(in_dico=True,table_type=0).order_by("rank")[0:n]
return entities
When I call the function (say with n=2), it returns the top 2 elements but I cannot access the second one because of this "not enough arguments to format string" error:
In [5]: d = Dictionary.objects.get(code='USA')
In [6]: top2 = d.get_topentities(2)
In [7]: top2
Out[7]: [<Entity: BARACK OBAMA>, <Entity: GOVERNMENT>]
In [8]: top2[0]
Out[8]: <Entity: BARACK OBAMA>
In [9]: top2[1]
.
.
/usr/local/lib/python2.7/dist-packages/django_pyodbc/compiler.pyc in as_sql(self, with_limits, with_col_aliases)
172 # Lop off ORDER... and the initial "SELECT"
173 inner_select = _remove_order_limit_offset(raw_sql)
--> 174 outer_fields, inner_select = self._alias_columns(inner_select)
175
176 order = _get_order_limit_offset(raw_sql)[0]
/usr/local/lib/python2.7/dist-packages/django_pyodbc/compiler.pyc in _alias_columns(self, sql)
339
340 # store the expanded paren string
--> 341 parens[key] = buf% parens
342 #cannot use {} because IBM's DB2 uses {} as quotes
343 paren_buf[paren_depth] += '(%(' + key + ')s)'
TypeError: not enough arguments for format string
In [10]:
My server backend is MSSQL and I'm using pyodbc as the database driver. If I try the same on a PC with engine sqlserver_ado, it works. Can someone help?
Regards,
Patrick

Disabling E_STRICT errors in CakePHP Beanstalk

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

Why is Logger crashing my Google Apps JSP?

I'm running Google Apps locally via eclipse. I connect to http://localhost:8888/ and sometimes Eclipse will throw an exception from this line 374 in AccessControlContext.class:
throw new AccessControlException("access denied "+perm, perm);
Here is the stack trace:
Thread [299085#qtp-12256262-2] (Suspended (exception AccessControlException))
AccessControlContext.checkPermission(Permission) line: 374
AccessController.checkPermission(Permission) line: 546
DevAppServerFactory$CustomSecurityManager(SecurityManager).checkPermission(Permission) line: 532
DevAppServerFactory$CustomSecurityManager.checkPermission(Permission) line: 289
DevAppServerFactory$CustomSecurityManager(SecurityManager).checkPackageAccess(String) line: 1512
Launcher$AppClassLoader.loadClass(String, boolean) line: 298
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: 247
ResourceBundle$RBClassLoader.loadClass(String) line: 435
ResourceBundle$Control.newBundle(String, Locale, String, ClassLoader, boolean) line: 2289
ResourceBundle.loadBundle(CacheKey, List<String>, Control, boolean) line: 1364
ResourceBundle.findBundle(CacheKey, List<Locale>, List<String>, int, Control, ResourceBundle) line: 1328
ResourceBundle.findBundle(CacheKey, List<Locale>, List<String>, int, Control, ResourceBundle) line: 1282
ResourceBundle.findBundle(CacheKey, List<Locale>, List<String>, int, Control, ResourceBundle) line: 1282
ResourceBundle.getBundleImpl(String, Locale, ClassLoader, ResourceBundle$Control) line: 1224
ResourceBundle.getBundle(String) line: 705
Level.getLocalizedName() line: 223
SimpleFormatter.format(LogRecord) line: 64
ConsoleHandler(StreamHandler).publish(LogRecord) line: 179
ConsoleHandler.publish(LogRecord) line: 88
Logger.log(LogRecord) line: 478
Logger.doLog(LogRecord) line: 500
Logger.log(Level, String) line: 523
Logger.warning(String) line: 1026
I'm calling just this:
log.warning("string");
and log is initialized like so:
private static final Logger log = Logger.getLogger(MyServletName.class.getName());
What is breaking?
Try using this line instead. I normally use something similar to the following line when I write GAE code:
private static final Logger log = Logger.getLogger(MyServletName.class.getSimpleName());
So, use getSimpleName() instead of getName(). Read java.lang.Class javadoc on getName() and getSimpleName(). The former probably appends an 'L' character to the end of the class type name, while the latter does not possess this (in your situation, undesirable) behaviour.
Also, consider using Guice Injection for the class's Logger object.

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