0

In my RedpCategory table I use cat_id as primaryKey, something like in my model below

in RedpCategory model:

<?php
   App::uses('AppModel', 'Model');
   class RedpCategory extends AppModel {
   public $useTable = 'redp_category';
   public $name = 'RedpCategory';
   public $primaryKey = 'cat_id';
//
//
}

in my view:

public function view($id = null) {
    if (!$id) {
        throw new NotFoundException(__('Invalid redeem category'));
    }

    $redp_categories = $this->RedpCategory->findById($id);
    if (!$redp_categories) {
        throw new NotFoundException(__('Invalid redeem category'));
    }
    $this->set('redp_categories', $redp_categories);
}

I got an error when I click on a category name link: "Undefined column: 7 ERROR: column RedpCategory.id does not exist"

How can I solve with this problem?

Any answer will be appreciated.Thank you in advanced.

Siemhong
  • 381
  • 1
  • 3
  • 19
  • http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#findby – CBroe Sep 01 '14 at 08:50
  • Thank you CBroe ! Actually, I saw this page previous time already, but not carefully read it, my bad! Now you make see it, thank you. – Siemhong Sep 01 '14 at 08:59

1 Answers1

4

findById() will search for the literal 'id' field.

Try switching your find statement to:

$this->RedpCategory->findByCatId($id);

Edit: redacted incorrect information

Nick Savage
  • 856
  • 1
  • 7
  • 18