user1522265
user1522265

Reputation: 1

cakephp 2.0 Fatal error: Call to a member function sort() on a non-object

Trying to be as specific as possible, as I got slammed last time I posted something!

Users authenticate and then in AppController I route them to a controller called Owners with the action being index code below

    public $components = array(                                                                         
  'Session',                                                                                    
  'Auth' => array(                                                                              
    'loginRedirect' => array('controller' => 'Owners', 'action' => 'index')                     
)    

I am new to Cake, but my guess is when the Owner Controller fires the code in the index function, it returns nothing and that is why I get the fatal error message in the view. (I am reading the Cakephp 2.0 cookbook) and yes there are several Owners in the owner table so its not empty.

mysql> select * from owners;
+----+-----------+-------------+----------+--------------------+----------+---------+-------+------- ------+---------+------------+-------------+
| id | firstname | middlename | lastname | streetaddress | city | zipcode | state | phonen umber | user_id | vehicle_id | citation_id |
+----+-----------+-------------+----------+--------------------+----------+---------+-------+------- ------+---------+------------+-------------+
| 1 | Mark | Walter | Simpson | 1234 Anytown | antonw | 12345 | Ge | 916123 456 | 1 | NULL | NULL |
| 2 | Frank | Dorthmuller | Frank | 2878 Bonlay Street | Fresno | 95758 | Ca | 916551 0234 | 3 | NULL | NULL |
| 3 | Toren | W | Valone | 8252 blind oak way | Belfower | 3889 | ca | 917838 8 | 1 | NULL | NULL |
| 4 | Toren | W | Valone | 8252 blind oak way | Belfower | 3889 | ca | 917838 8 | 1 | NULL | NULL |
+----+-----------+-------------+----------+--------------------+----------+---------+-------+------- ------+---------+------------+-------------+
4 rows in set (0.00 sec)

In the Owners controller I put this following code in the index function,

     public function index() {                                                                   

          $this->set('owners', $this->Owner->find('all'));                                      
    }

When I login as a user I get this, Owners

Notice (8): Undefined property: View::$Paginator [CORE/Cake/View/View.php, line 804]

Fatal error: Call to a member function sort() on a non-object in /srv/www/www.cross-town-traffic-software.com/public_html/freecite/app/View/Owners/index.ctp on line 5

Here is line five from the index.ctp file in the owners directory

<th><?php echo $this->Paginator->sort('id');?></th>      

Upvotes: 0

Views: 2237

Answers (2)

JohnyWind
JohnyWind

Reputation: 63

In the controller you have to add

public $components = array('Paginator');

instead of

public $helpers = array('Paginator');

Upvotes: 0

pixelistik
pixelistik

Reputation: 7830

You are trying to use the PaginatorHelper in your view, but have not included it.

Add

public $helpers = array('Paginator');

to your controller. See Cookbook for background on Helpers and how to use them in your views.

Upvotes: 2

Related Questions