简体   繁体   中英

How to get the id of recently viewed record to do a cgridview which is unique to each record in yii?

I know this is unusual but I want either a cgridview that is unique to each record or an alternative way of doing the thing that I want...

I have a cgridview which displays a list of patients

在此处输入图片说明

when the view button is clicked it would go the view page... My view page has an operation on the sidebar called "Display Patient Records of this Patient" and I wanted it to redirect to another cgridview from another model.

The problem now is the cgridView displays all of the patient records instead of just the record of the patient, the user viewed.

Is there a way to get the id of the recently viewed patient record so I can come up with a new dataProvider for this?

take note that I need the id of the recently viewed patient, not the id of the user logged in so I can't just use

Yii::app()->user->id;

I would appreciate any help or another alternative of achieving this...

// model view id
$id=$model->id;

When the view button is clicked on the Manage Patients grid view, In that view page, I hope you have the new menu item set, something similar to:

array('label'=>'Display Patient Records', 'url'=>array('/controller/patientRecord','id'=>Yii::app()->request->getParam('id');)),

Here Yii::app()->request->getParam('id'); will return you the id of the patient being viewed controller is your controller name and patientRecord is your action name which will return the grid view of the patient's records.

In the action patientRecord just render the new grid view passing the patient id value to the view, create a new function in your model, similar to the normal search function you have in a model, just add a condition:

$criteria->condition = "patient_id='$id' ";

When you call the model->search() in your grid view page, pass the id you have, something like: $model->search($id),

I hope this gives you an idea. :)

Since you already create different id's for each record, you just need to get them in controller like $chosenRecord = modelName::model()->findByPk($idOfChosenRecord);

you will render to your second View so model() won't create a problem. Make sure other model contains $id in relations to. You may want to consider using a second Controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM