我想通過我的控制器和模型來做最簡單的調用,但它不起作用。CakePHP 2 - 爲什麼我在模型函數中出現sql錯誤?
我得到的錯誤是:
Error: 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 'ppLongerFunction2' at line 1
控制器代碼:
<?php
class UsersController extends AppController{
public $uses = array('User');
function test(){
$blah = $this->User->find('all');
$u = $this->User->ppLongerFunction2();
$this->set(compact('blah', 'u'));
}
}
和模型是:
<?php
class User extends AppModel{
public var $name = 'User';
var $displayField = 'username';
var $useTable = 'users';
public function ppLongerFunction2(){
$something = $this->find('all');
return $something;
}
}
我在哪裏搞亂?
堆棧跟蹤:
#0 C:\wamp\www\lib\Cake\Model\Datasource\DboSource.php(436): PDOStatement->execute(Array)
#1 C:\wamp\www\lib\Cake\Model\Datasource\DboSource.php(403): DboSource->_execute('ppLongerFunctio...', Array)
#2 C:\wamp\www\lib\Cake\Model\Datasource\DboSource.php(647): DboSource->execute('ppLongerFunctio...', Array, Array)
#3 C:\wamp\www\lib\Cake\Model\Datasource\DboSource.php(589): DboSource->fetchAll('ppLongerFunctio...', Array, Array)
#4 C:\wamp\www\lib\Cake\Model\Model.php(720): DboSource->query('ppLongerFunctio...', Array, Object(AppModel))
#5 C:\wamp\www\app\Controller\UsersController.php(11): Model->__call('ppLongerFunctio...', Array)
#6 C:\wamp\www\app\Controller\UsersController.php(11): AppModel->ppLongerFunction2()
#7 [internal function]: UsersController->test()
#8 C:\wamp\www\lib\Cake\Controller\Controller.php(473): ReflectionMethod->invokeArgs(Object(UsersController), Array)
#9 C:\wamp\www\lib\Cake\Routing\Dispatcher.php(104): Controller->invokeAction(Object(CakeRequest))
#10 C:\wamp\www\lib\Cake\Routing\Dispatcher.php(86): Dispatcher->_invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse))
#11 C:\wamp\www\app\webroot\index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#12 {main}
所有固定。這是一個文件名。感謝您的幫助:|愚蠢的
它創建的SQL查詢是什麼? (如果您還沒有安裝DebugKit,那麼對於任何CakePHP項目來說都是必須的,並且可以輕鬆地爲您提供所有這些信息 - 變量,mysql查詢運行...等等) – Dave 2012-02-20 14:10:52
也可能不是主要問題,因爲你在UsersController中,所以用戶需要$ use。 – Dave 2012-02-20 14:12:09
我沒有debutKit,另一種方式,我可以告訴你這個查詢嗎? – mgPePe 2012-02-20 14:20:46