php - Cannot call set or create from with in a Model class in CakePHP? -
i'm working in cakephp model class, writing function supposed perform whole bunch of manipulations on model. i'm trying follow skinny controller, fat model idea. however, don't seem able call any of model's functions in model. hasn't been initialized yet, because sql error when do:
warning (512): sql error: 1064: have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 1 [core/cake/libs/model/datasources/dbo_source.php, line 681] query: show full columns
it looks if table name hasn't been set internally somewhere. model looks this:
class search extends appmodel { var $name='search'; var $hasmany = 'searchresult'; var $actsas = array('containable'); function search($query) { $this->create(); $this->set('query', $query); $this->save(); } }
i know model needs has been created works find, because calling exact same sequence of functions works fine model controller. so:
function search($query) { $this->search->create(); $this->search->set('query', $query); $this->search->save(); }
that works fine. gives? what's going on here?
what trying set()
method? method name exist both model
& controller
, i've never had reason use in model
context. moreover, particular use looks belongs in controller
context (though that's educated guess @ best).
if you're trying set variable named query
can accessed view, needs in controller. create()
, save()
, of course, staples of model
context.
Comments
Post a Comment