Call to undefined method PaginatorComponent::paginate() cakephp2 - php

I'm upgrading my cakephp1.x project to cakephp2.10.12. I got below error when I try to apply pagination to my view
Error
Call to undefined method PaginatorComponent::paginate()
My controller code like this
App::uses('Controller', 'Controller');
class ProductsController extends AppController {
var $name = "Product";
var $helpers = array('Html', 'Form','Paginator','Js');
var $paginate = array('limit' => 25,'order' => array('Product.pname' => 'asc'));
function allproducts() {
$this->paginate = array(
'conditions' => array("Product.status" => 'A','Product.stock >' => 0),
);
$this->Paginator->settings = $this->paginate;
list($order,$limit,$page) = $this->paginate(); // Added

Related

Is possible to associate models with current time conditions?

Is possible to get two models associated with current time condition?
<?php
class SomeModel extends AppModel {
public $hasOne = array(
'ForumBan',
'ForumBanActive' => array(
'className' => 'ForumBan',
'conditions' => array('ForumBanActive.end_time >' => time()) // fatal error
),
);
}
I don't want to add this condition every time i call find on ForumBan model.
Basic lesson in php OOP: You can't call methods and functions in object property declarations. http://php.net/manual/en/language.oop5.properties.php
Set the association in the __construct() method of the model or use bindModel():
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->hasOne['ForumBanActive']['conditions'] = array('ForumBanActive.end_time >' => time()));
}
public $hasOne = Array(
'ForumBan',
'ForumBanActive' => array('className' => 'ForumBan'),
'UserFile',
'BlogProfile',
);
like i said, thanks #burzum for advice, but copy-past solution from my answer isn't cool, shame on you!
Following #burzum answer i got wanted result.
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->hasOne['ForumBanActive']['conditions'] = array('ForumBanActive.end_time >' => time()));
}
public $hasOne = Array(
'ForumBan',
'ForumBanActive' => array('className' => 'ForumBan'),
'UserFile',
'BlogProfile',
);

Creating relationship between 2 tables in CakePHP using models to write less code

I try to say just CkMmUsersKta.user_id=CkSetupUser.id and define relationship between 2 tables in CakePhp.
I defined models and called models in function in controller but says Undefined index for
$c['CkSetupUser']['user_name']
CakePHP's
Notice (8): Undefined index: CkSetupUser [APP\Controller\RealsController.php, line 67]
my controller:
class RealsController extends AppController {
public $helpers = array('Html', 'Form');
public $uses =array('CkMmUsersKta','CkSetupUser');
public function index(){
$this>loadModel('CkMmUsersKta');$this>loadModel('CkSetupUser');
ini_set('memory_limit', '2000M');
$cs=$this->CkMmUsersKta->find("all",array('fields'=>array('CkMmUsersKta.id')));
foreach($cs as $c):
echo $c['CkMmUsersKta']['id'].$c['CkSetupUser']['user_name']."<br />";
endforeach;
set_time_limit(0);
}
}
my CkSetupUser model:
public $hasMany = array(
'CkMmUsersKta' => array(
'className' => 'CkMmUsersKta',
'foreignKey' => 'user_id',
'dependent' => true
)
);
my CkMmUsersKta model:
public $belongsTo = array(
'CkSetupUser' => array(
'className' => 'CkSetupUser',
'foreignKey' => 'user_id'
)
);
The problem is that you are fetching only id field in:
$cs=$this->CkMmUsersKta->find("all",array('fields'=>array('CkMmUsersKta.id')));
You should specify the name field also.
$cs=$this->CkMmUsersKta->find("all",array('fields'=>array('CkMmUsersKta.id','CkSetupUser.user_name')));

Containable behavior only working when local

I'm having a very strange issue. I'm working with XAMPP on my local computer, and everything works perfect. But when I upload it to my server, suddenly ContainableBehavior stops recognizing associations.
Cake's version: 2.5.6
Here's XAMPP's phpinfo(): http://pastebin.com/DeZWMh42
And here's my server's phpinfo(): http://pastebin.com/rtZ0kTAM
Both locations have the exact same files and databases.
This is the error(s) I'm getting:
Warning (512): Model "Certificado" is not associated with model
"Usuario" [CORE/Cake/Model/Behavior/ContainableBehavior.php, line 342]
Warning (512): Model "Certificado" is not associated with model
"Alumno" [CORE/Cake/Model/Behavior/ContainableBehavior.php, line 342]
Warning (512): Model "Certificado" is not associated with model
"Usuario" [CORE/Cake/Model/Behavior/ContainableBehavior.php, line 342]
Warning (512): Model "Certificado" is not associated with model
"Alumno" [CORE/Cake/Model/Behavior/ContainableBehavior.php, line 342]
Basically, an Impresion belongs to an Usuario and to a Certificado, the latter also belongs to an Usuario (may be a different one) and to an Alumno. Obviously I cut out all the irrelevant parts (let me know if you need more.)
This is where I'm using ContainableBehavior (Impresion's Controller):
(I'm getting the error on /impresions/index)
class ImpresionsController extends AppController {
public $components = array('Paginator');
public $uses = array('Usuario', 'Alumno', 'Certificado', 'Impresion');
public function index(){
$this->paginate = array(
'limit' => 10,
'order' => array('fecha_creacion' => 'desc'),
'contain'=>array(
'Usuario',
'Certificado' => array(
'Usuario',
'Alumno'
)
),
);
$results = $this->paginate('Impresion');
$this->set('impresiones',$results);
}
}
And in the view I just use a foreach($impresiones).
Impresion's Model:
class Impresion extends AppModel {
public $actsAs = array('Containable');
public $belongsTo = array(
'Certificado' => array(
'className' => 'certificado',
'foreignKey' => 'certificado_id',
),
'Usuario' => array(
'className' => 'Usuario',
'foreignKey' => 'usuario_id',
'fields' => array('nombre','codigo')
),
);
}
Usuario's Model:
class Usuario extends AppModel {
public $hasMany = array('Certificado','Impresion');
public $actsAs = array('Containable');
}
Certificado's Model:
class Certificado extends AppModel {
public $actsAs = array('Containable');
public $belongsTo = array(
'Usuario' => array(
'className' => 'Usuario',
'foreignKey' => 'usuario_id',
),
'Alumno' => array(
'className' => 'Alumno',
'foreignKey' => 'alumno_id',
)
);
public $hasMany = 'Impresion';
}
Alumno's Model:
class Alumno extends AppModel {
public $actsAs = array('Containable');
public $hasMany = 'Certificado';
}
Local query: http://pastebin.com/B5MRp3FS
Server's query: http://pastebin.com/J2H4U6Ge
I'm completely lost here. Why does it work perfectly fine on my computer, but breaks on the server? Everything else works, it's just ContainableBehavior that's having problems.
I can't believe it.
Disregard everything.
This:
'className' => 'certificado',
Should've been this:
'className' => 'Certificado',
Sorry for wasting your time, I'm an idiot

cackphp multiple pagination with same page Error: An Internal Error Has Occurred

My system has users with different role. I want show all users in same page in separate tables. So i did following things.
User Model (User.php)
App::uses('AppModel', 'Model');
class User extends AppModel {
public $useTable = 'users';
}
AUser model (Auser.php)
App::uses('User', 'Model');
class Auser extends User {
}
BUser model (Buser.php)
App::uses('User', 'Model');
class Buser extends User {
}
UsersController.php
App::uses('Auser', 'Model');
App::uses('Buser', 'Model');
class UsersController extends AppController {
public function index() {
$Auser = new Auser();
$Buser = new Buser();
$this->paginate = array(
'Auser' => array(
'conditions' => array('Auser.role' => 0),
'limit' => 5
),
'Buser' => array(
'conditions' => array('Buser.role' => 1),
'limit' => 5
),
);
$this->set('ausers', $this->paginate('Auser'));
$this->set('busers', $this->paginate('Buser'));
}
}
But it show following error.
Error: An Internal Error Has Occurred.
What is the issue?
error comma and how to load models is so
$this->loadModel('Auser');
so:
class UsersController extends AppController {
public function index() {
$this->loadModel('Auser');
$this->loadModel('Buser');
$this->paginate = array(
'Auser' => array(
'conditions' => array('Auser.role' => 0),
'limit' => 5
),
'Buser' => array(
'conditions' => array('Buser.role' => 1),
'limit' => 5
)
);
$this->set('ausers', $this->paginate('Auser'));
$this->set('busers', $this->paginate('Buser'));
}
}

unable to keep pagination track

Pagination links are shown correctly for 1st time, but when I click 2nd page link the data vanishes.
Here is my code:
Controller
class PostsController extends AppController {
public $components = array('Paginator');
var $paginate = array(
'Post' => array(
'limit' => 5
)
);
public function index() {
//debug("in index");
//$this->render();
$d=$this->data['lower_limit'];
//debug(" df ");
//debug($d);
$lower= $this->data['lower_limit'];
$upper= $this->data['upper_limit'];
$conditions = array('Post.post_id >=' => $lower, 'Post.post_id <=' => $upper);
$this->Paginator->settings = $this->paginate;
$data = $this->Paginator->paginate('Post', $conditions);
$this->set('data', $data);
$this->set('lower_limit',$lower);
$this->set('upper_limit', $upper);
}
}
Model
I have not overridden paginate and pagination count methods.

Categories