【问题标题】:CakePHP var $useTable = false still produces "Base table or view not found: 1146 ..." errorCakePHP var $useTable = false 仍然产生“未找到基表或视图:1146 ...”错误
【发布时间】:2012-07-27 13:10:25
【问题描述】:

我无法解决这个问题,我宁愿不必用 unBinds 填充我的控制器。我有一个需要验证的贤者薪酬表格。因此,我建立了一个圣人模型,内容如下:

class Sage extends AppModel {

    var $useTable = false;
    var $_schema = array(
        'CardHolderName'        =>array('type'=>'string', 'length'=>100), 
        'CardType'      =>array('type'=>'string', 'length'=>100), 
        'CardNumber'        =>array('type'=>'string', 'length'=>100), 
        'EndMonth'      =>array('type'=>'string', 'length'=>100), 
        'EndYear'       =>array('type'=>'string', 'length'=>100), 
        'BILLING_address_line_1'        =>array('type'=>'string', 'length'=>100), 
        'BILLING_city'      =>array('type'=>'string', 'length'=>100), 
        'BILLING_county'        =>array('type'=>'string', 'length'=>100), 
        'BILLING_country'       =>array('type'=>'string', 'length'=>100), 
        'BILLING_country'       =>array('type'=>'string', 'length'=>100), 
        'BILLING_post_code'     =>array('type'=>'string', 'length'=>100), 
        'DELIVER_name'      =>array('type'=>'string', 'length'=>100), 
        'DELIVER_address_line_1'        =>array('type'=>'string', 'length'=>100), 
        'DELIVER_city'      =>array('type'=>'string', 'length'=>100), 
        'DELIVER_county'        =>array('type'=>'string', 'length'=>100), 
        'DELIVER_country'       =>array('type'=>'string', 'length'=>100), 
        'DELIVER_post_code'     =>array('type'=>'string', 'length'=>100), 
        'CSV'       =>array('type'=>'string', 'length'=>3)

    );

    public $validate = array(
        'CardHolderName'=>array(
            'Please enter your name.'=>array(
                'rule'=>'notEmpty',
                'message'=>'Please enter your name.'
            )
        ),
        'CardType'=>array(
            'Card Type Select'=>array(
                'rule'=>'notEmpty',
                'message'=>'You must select a card type.'
            )
        ),
        'CardNumber'=>array(
            'Card Number Length'=>array(
                'rule'=> array('between', 16, 20),
                'message'=>'Card numbers are at least 16 numbers long.'
            ),
            'Not empty'=>array(
                'rule'=> 'notEmpty',
                'message'=>'Card Number is missing.'
            ),
            'Is a number' => array(
                'rule' => 'numeric',
                'message' => 'This must be a number (no spaces either).'
            )
        ),
        'EndMonth'=>array(
            'End Month Select'=>array(
                'rule'=>'notEmpty',
                'message'=>'No Month.'
            )
        ),
        'EndYear'=>array(
            'End Year Select'=>array(
                'rule'=>'notEmpty',
                'message'=>'No Year.'
            )
        ),
        'CSV'=>array(
            'Card Number Length'=>array(
                'rule'=> array('between', 3, 3),
                'message'=>'A CSV is 3 numbers long.'
            ),
            'CSV not empty'=>array(
                'rule'=>'notEmpty',
                'message'=>'Please enter your security code.'
            ),
            'Is a number' => array(
                'rule' => 'numeric',
                'message' => 'A CSV is 3 numbers long.'
            )
        )
    );
}

但是当我转到订单的索引页面(其中有一个$this->paginate('Order');)时,我得到以下信息:

错误:SQLSTATE[42S02]:未找到基表或视图:1146 表 'wr_shop.sages' 不存在

SQL 查询:SELECT COUNT(*) AS count FROM wr_shop.orders AS Order 左连接 wr_shop.users AS User ON (Order.user_id = User.id) 左连接 wr_shop.baskets AS Basket ON (Basket.order_id = Order.id) 左连接wr_shop.sages AS Sage 开 (Sage.order_id = Order.id) 其中 1 = 1

谁能告诉我我错过了什么,我似乎无法在任何地方在线找到答案。

---UPADATE--- 我已经通过创建一个“sages”表临时解决了这个问题,即使它永远不会保存任何数据。

【问题讨论】:

  • 顺便说一句,我对 Cake 还很陌生。

标签: model cakephp-2.0


【解决方案1】:

您的 Sage 模型未正确加载,而是使用了 AppModel 实例。

检查路径、文件名和文件扩展名:app/Model/Sage.php

【讨论】:

  • 路径和文件是正确的,唯一能让我开心的方法就是拥有一个空的 'sages' 数据库,尽管有 var $useTable = false;
  • 感谢您以前所未有的方式回答。
【解决方案2】:

今天我遇到了同样的问题,就我而言,问题是我的表单发送了 ID 字段。当我删除 ID 字段时,验证执行得很好。

【讨论】:

    猜你喜欢
    • 2017-08-02
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    相关资源
    最近更新 更多