我收到此错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set_origin' at line 1
当我在 OrderItems Controller 中添加此行时,会发生此错误。
$products = $this->OrderItem->Product->find('all');
我不知道要改变什么。
如果我尝试$products = $this->OrderItem->Product->find('list');
,错误就消失了。但我需要使用 find('all') 方法。
谁能帮帮我。提前致谢。
设置原点
APP\Vendor\dompdf\include\stylesheet.cls.php 第 218 行 → Model->__call(string, array)
'设置原点' 大批( (整数)0 => (整数)1 )
2.APP\Vendor\dompdf\include\stylesheet.cls.php 第 218 行 → Style->set_origin(integer)
else
$this->_styles[$key] = clone $style;
$this->_styles[$key]->set_origin( $this->_current_origin );
}
pdf/default.ctp
<?php
require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
spl_autoload_register('DOMPDF_autoload');
$dompdf = new DOMPDF();
$dompdf->set_paper = 'A4';
$dompdf->set_paper("a4", "landscape");
$dompdf->load_html(utf8_decode($content_for_layout), Configure::read('App.encoding'));
$dompdf->render();
echo $dompdf->output();
错误日志
2014-02-03 09:29:17 Error: [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set_origin' at line 1
Request URL: /mall/orderItems/receipt_pdf/201.pdf
Stack Trace:
#0 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(460): PDOStatement->execute(Array)
#1 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(426): DboSource->_execute('set_origin', Array)
#2 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(666): DboSource->execute('set_origin', Array, Array)
#3 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(611): DboSource->fetchAll('set_origin', Array, Array)
#4 C:\xampp\htdocs\mall\lib\Cake\Model\Model.php(799): DboSource->query('set_origin', Array, Object(Style))
#5 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(218): Model->__call('set_origin', Array)
#6 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(218): Style->set_origin(1)
#7 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(1340): Stylesheet->add_style('html', Object(Style))
#8 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(1077): Stylesheet->_parse_sections('html { ? displ...')
#9 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(307): Stylesheet->_parse_css('/**? * dompdf d...')
#10 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\dompdf.cls.php(535): Stylesheet->load_css_file('C:/xampp/htdocs...', 1)
#11 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\dompdf.cls.php(696): DOMPDF->_process_html()
#12 C:\xampp\htdocs\mall\app\View\Layouts\pdf\default.ctp(8): DOMPDF->render()
#13 C:\xampp\htdocs\mall\lib\Cake\View\View.php(945): include('C:\xampp\htdocs...')
#14 C:\xampp\htdocs\mall\lib\Cake\View\View.php(907): View->_evaluate('C:\xampp\htdocs...', Array)
#15 C:\xampp\htdocs\mall\lib\Cake\View\View.php(535): View->_render('C:\xampp\htdocs...')
#16 C:\xampp\htdocs\mall\lib\Cake\View\View.php(479): View->renderLayout('', 'default')
#17 C:\xampp\htdocs\mall\lib\Cake\Controller\Controller.php(952): View->render(NULL, NULL)
#18 C:\xampp\htdocs\mall\lib\Cake\Routing\Dispatcher.php(194): Controller->render()
#19 C:\xampp\htdocs\mall\lib\Cake\Routing\Dispatcher.php(162): Dispatcher->_invoke(Object(OrderItemsController), Object(CakeRequest), Object(CakeResponse))
#20 C:\xampp\htdocs\mall\app\webroot\index.php(110): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#21 {main}
OrderItem 模型如下所示:
<?php
App::uses('AppModel', 'Model');
/**
* OrderItem Model
*
* @property Order $Order
* @property Product $Product
*/
class OrderItem extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'id';
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Order' => array(
'className' => 'Order',
'foreignKey' => 'order_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Product' => array(
'className' => 'Product',
'foreignKey' => 'product_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
最佳答案
您的问题很可能是命名冲突,其中 DOMPDF 上下文中使用的类名与您已加载的模型类之一相同,从堆栈跟踪和 DOMPDF 代码来看,这将是一个名为 的类样式
。
该问题仅在使用 find('all')
时出现,表明有问题的模型类在某种程度上与您的 Product
或 Order 有关
模型(或者在 AppModel
类中甚至可能存在关联?),因为 find('list')
显式排除关系(通过使用 recursive = -1
)。
如果您没有名为 Style
的模型类,请调试 $this->_styles[$key]
的类型以计算出确切的类名,然后通过重命名模型或样式类(如果可能)来解决冲突。
关于php - Cakephp SQLSTATE[42000] : Syntax error or access violation: 1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21522157/