简体   繁体   English

如何获取最近查看记录的ID来进行yii中每个记录唯一的cgridview?

[英]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... 我知道这很不正常,但我希望每个记录都具有唯一的cgridview或执行我想要的事情的另一种方式...

I have a cgridview which displays a list of patients 我有一个cgridview显示患者列表

在此处输入图片说明

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. 当单击查看按钮时,它将进入查看页面...我的查看页面在侧栏上有一个名为“显示该患者的患者记录”的操作,我希望它从其他模型重定向到另一个cgridview。

The problem now is the cgridView displays all of the patient records instead of just the record of the patient, the user viewed. 现在的问题是,cgridView显示所有的患者记录,而不仅仅是用户查看的患者记录。

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? 有没有一种方法可以获取最近查看过的患者记录的ID,以便为此提供一个新的dataProvider?

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 请注意,我需要最近查看过的患者的ID,而不是登录用户的ID,因此我不能只使用

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: 在“ Manage Patients网格视图上单击视图按钮后,在该视图页面中,希望您设置了新的菜单项,类似于:

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

Here Yii::app()->request->getParam('id'); 这里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. 将返回您正在查看的患者的ID controller是您的控制器名称,而patientRecord是您的操作名称,它将返回患者记录的网格视图。

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: 在action patientRecord动作中,只需呈现将病人ID值传递到视图的新网格视图,即可在模型中创建一个新功能,类似于模型中的普通search功能,只需添加一个条件即可:

$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), 当您在网格视图页面中调用model->search()时,传递您拥有的id ,例如: $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); 由于您已经为每个记录创建了不同的ID,因此只需要将它们添加到$chosenRecord = modelName::model()->findByPk($idOfChosenRecord);

you will render to your second View so model() won't create a problem. 您将渲染到第二个View,因此model()不会产生问题。 Make sure other model contains $id in relations to. 确保其他模型包含与$ id的关系。 You may want to consider using a second Controller. 您可能要考虑使用第二个控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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