2014-06-20 36 views
0

我做一個應用程序,顯示一些價格爲註冊人的產品。 當創建產品頁面顯示我「數據庫錯誤」 「錯誤:SQLSTATE [42S22]:列未找到:1054未知列‘Product.utype’在‘where子句’」沒有數據庫錯誤的產品控制器如何42S22

我的ProductsController是這樣的:

class ProductsController extends AppController { 


    public function index() { 
     $this->Product->recursive = 0; 

     $products = $this->Product->find('all'); 
     $this->set('products', $Product); 

    } 

    /** 
    * view method 
    * 
    * @throws NotFoundException 
    * @param string $id 
    * @return void 
    */ 

    public function view($id = null) { 
     $this->Product->id = $id; 
      if (!$this->Product->exists()) { 
       throw new NotFoundException(__('Invalid Product')); 
      } 
     $this->set('products', $this->Product->read(null, $id)); 
    } 
} 

和模型Product.php是這樣的:

class Product extends AppModel { 
public $primaryKey = 'id_prod'; 
/** 
* belongsTo associations 
* 
* @var array 
*/ 
    public $belongsTo = array(
     'Occurrence' => array(
      'className' => 'Occurrence', 
      'foreignKey' => 'occurrence_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ), 
     'User' => array(
      'className' => 'User', 
      'foreignKey' => 'user_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 
} 

能幫助我,好嗎? 謝謝。

回答

1

每非常明確的錯誤:

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Product.utype' in 'where clause'"

您的代碼正在尋找在products表科拉姆「UTYPE」(這顯然不存在)。如果你不確定你的代碼告訴它它在做什麼,只需在項目範圍內搜索「utype」並將其更新爲正確的字段名稱即可。

相關問題