Reputation: 1
So I am trying to get a find table into my elements view and I am doing that by making a helper function in my Tags controller.
<?php
class TagsController extends AppController {
var $name = 'Tags';
function gettags(){
if (!empty($this->params['requested'])) {
return $this->Tag->find('list', array('fields'=>'Tag.tag_name'));
}
return false;
}
}
And then in my view, I call
<? $tags = $this->requestAction('/tags/gettags'); debug($tags); ?>
However, it returns the error
Warning (512): SQL Error: 1054: Unknown column 'Tag.tag_name' in 'field list' [CORE/cake/libs/model/datasources/dbo_source.php, line 684] Query: SELECT
Tag
.id
,Tag
.tag_name
FROMusers
ASTag
WHERE 1 = 1
which means that it thinks my tags table is actually users. This doesn't happen in the Tags view. Anyone have any ideas as to what I'm doing wrong? The tables aren't associated with either other or anything.
My Tag model is:
<?php
class Tag extends AppModel {
var $name = 'Tag';
var $hasMany = array(
'BrandTag' => array(
'className' => 'BrandTag',
'foreignKey' => 'tag_id',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
));
}
?>
Upvotes: 0
Views: 118
Reputation: 1529
Dao it may be worth going into you app/tmp/cache folder and deleting the files in the model folder. You may have cached a corrupt model.
Upvotes: 0
Reputation: 114
Something like this should work:
$this->getModel('Tag')->find('list', array('fields'=>'Tag.tag_name');
As said you shouldn't be retrieving from a view like this, it's not good MVC practice.
If the Tag code will be retrieved by multiple controllers you should consider creating a component which these controllers can load as needed.
Upvotes: 1