在我的数据库中有一个内容表,当从此表中获取数据时,我想将字段 url 追加到结果中,该结果基于 slug 字段,包含在表中。无论如何,我已经看到了在之前版本的cakephp中使用此表的模型的行为,然后在行为类中的afterFind回调中修改结果的方法。但是在版本3中没有afterFind回调,他们建议在手册中使用mapReduce()方法,但是这个方法在手册中解释不清楚,我无法弄清楚如何使用mapReduce()实现这一点。
答案 0 :(得分:1)
经过一些研究后,我意识到附加url字段字段以查找结果的最佳方法是使用 formatResults 方法,这就是我在查找器中所做的:
String[] proj = { MediaStore.Video.Media.DATA };
String result = null;
CursorLoader cursorLoader = new CursorLoader(
getActivity(),
uri, proj, null, null, null);
Cursor cursor = cursorLoader.loadInBackground();
if(cursor != null){
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
result = cursor.getString(column_index);
Log.d("file path", result);