开发者

CakePHP - Using Model::read() on a model with no table

I have a model with $useTable = false and a custom $schema defined.

I am trying to keep everything as integral to the framework as possible, by using standard model methods, even though there is no table. So, for example, I am using Model::save() to update the $data array of the model.

However, from a controller I am trying to use Model::read(), but it is failing I think because read() doesn't have an ID in the model. Is there any way to simulate IDs in 开发者_C百科the model without a table? I know I can access the data I want through $this->Model->data['Model']['field'] but I feel that is not good practice.


read() is for when you're retrieving data based on the primary key, or id.

If you're trying to read data from the underlying datasource (whatever that may be) but there's no primary key, then perhaps find('first', ...) is what you might want.

If you do have a primary key, but it's not called 'id' (perhaps 'field'), then assign var $primaryKey = 'field'; in the model, and you should be fine to use read, based on that field data.

Incidentally, what is the underlying data source?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜