Hello all, thank you in advance for any help you may be able to provide.
I'm using cakePHP 2.2.1
The following code works perfectly:
class OptionsController extends AppController {
var $uses = array('Option', 'ShooterEvent', 'ShooterOption');
public function calc($id) {
$paid_entries = $this->ShooterEvent->getPaidEntries($event_id);
$paid_options = $this->ShooterOption->find('all');
$something = 'Default answer';
$this->set(compact('paid_entries', 'something', 'paid_options'));
}
The following change will die horribly:
// Made to class above
$something = 'Default answer';
$something = $this->ShooterOption->getSomething(1);
// Made to the ShooterOption class
class ShooterOption extends AppModel {
function getSomething($option_id) {
return 1;
}
}
The error is: *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
'getSomething' at line 1
The debug trace shows:
Stack Trace
- CORE\Cake\Model\Datasource\DboSource.php line
461<http://ezshoot_v5:8080/admin/options/calculate/1#>→
PDOStatement->execute(array)<http://ezshoot_v5:8080/admin/options/calculate/1#>
try { $query = $this->_connection->prepare($sql,
$prepareOptions); $query->setFetchMode(PDO::FETCH_LAZY);
if (!$query->execute($params)) { $this->_results = $query;
array(
(int) 0 => (int) 1
)
- CORE\Cake\Model\Datasource\DboSource.php line
427<http://ezshoot_v5:8080/admin/options/calculate/1#>→
DboSource->_execute(string,
array) <http://ezshoot_v5:8080/admin/options/calculate/1#>
$options += array('log' => $this->fullDebug); $t =
microtime(true); $this->_result = $this->_execute($sql, $params);
'getSomething'
array(
(int) 0 => (int) 1
)
- CORE\Cake\Model\Datasource\DboSource.php line
671<http://ezshoot_v5:8080/admin/options/calculate/1#>→
DboSource->execute(string,
array, array) <http://ezshoot_v5:8080/admin/options/calculate/1#>
if ($cache && ($cached = $this->getQueryCache($sql, $params)) !==
false) { return $cached; } if ($result =
$this->execute($sql, array(), $params)) { $out = array();
'getSomething'
array()
array(
(int) 0 => (int) 1
)
- CORE\Cake\Model\Datasource\DboSource.php line
613<http://ezshoot_v5:8080/admin/options/calculate/1#>→
DboSource->fetchAll(string,
array, array) <http://ezshoot_v5:8080/admin/options/calculate/1#>
} else { $cache = true; }
return $this->fetchAll($args[0], $args[1], array('cache' =>
$cache)); }
'getSomething'
array(
(int) 0 => (int) 1
)
array(
'cache' => object(AppModel) {}
)
- CORE\Cake\Model\Model.php line
784<http://ezshoot_v5:8080/admin/options/calculate/1#>→
DboSource->query(string,
array, AppModel) <http://ezshoot_v5:8080/admin/options/calculate/1#>
if ($result !== array('unhandled')) { return $result;
} $return = $this->getDataSource()->query($method, $params, $this);
return $return;
'getSomething'
array(
(int) 0 => (int) 1
)
object(AppModel) {
useDbConfig => 'default'
useTable => 'shooter_options'
id => false
data => array([maximum depth reached])
schemaName => 'shoots'
table => 'shooter_options'
primaryKey => 'id'
validate => array([maximum depth reached])
validationErrors => array([maximum depth reached])
validationDomain => null
name => 'ShooterOption'
alias => 'ShooterOption'
tableToModel => array(
[maximum depth reached]
)
cacheQueries => false
belongsTo => array([maximum depth reached])
hasOne => array([maximum depth reached])
hasMany => array([maximum depth reached])
hasAndBelongsToMany => array([maximum depth reached])
actsAs => null
Behaviors => object(BehaviorCollection) {}
whitelist => array([maximum depth reached])
cacheSources => true
findQueryType => null
recursive => (int) 1
order => null
virtualFields => array([maximum depth reached])
__backAssociation => array([maximum depth reached])
__backInnerAssociation => array([maximum depth reached])
__backOriginalAssociation => array([maximum depth reached])
__backContainableAssociation => array([maximum depth reached])
findMethods => array(
[maximum depth reached]
)
tablePrefix => ''
}
- APP\Controller\OptionsController.php line
199<http://ezshoot_v5:8080/admin/options/calculate/1#>→ Model->__call(string,
array) <http://ezshoot_v5:8080/admin/options/calculate/1#>
$paid_options = $this->ShooterOption->find('all'); $something =
'Default answer'; $something = $this->ShooterOption->getSomething(1);
'getSomething'
array(
(int) 0 => (int) 1
)
- APP\Controller\OptionsController.php line
199<http://ezshoot_v5:8080/admin/options/calculate/1#>→
AppModel->getSomething(integer)<http://ezshoot_v5:8080/admin/options/calculate/1#>
$paid_options = $this->ShooterOption->find('all'); $something =
'Default answer'; $something = $this->ShooterOption->getSomething(1);
(int) 1
It's trying to execute the sql statement "getSomething." It's as if it
can't find the function in the Model? Any ideas would be greatly
appreciated.
Thanks
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.