douao3063 2014-09-29 08:58
浏览 23

在GridView Yii2中过滤索引视图上的结果

I have a set of 'clients' and they are displayed in a GridView. 'Clients' can not be deleted by the average user, only marked for deletion. However I would like it so they are not displayed in the list once they are marked for deletion.

I am using Yii2, and the soft deletion table contains has three columns that concern the data 'foreign_table', 'foreign_column' and 'foreign_value'. It is set up like so as I do not want to delete data from the 'Clients' table unless it is needed.

How would I go about filtering the results of the GridView?

Would I use $model->search?

  • 写回答

2条回答 默认 最新

  • doutuo2829 2014-11-26 07:29
    关注

    So you have a table where you save references to items that should be considered as deleted.

    I think it could be reasonable to override find() of the Client class since there could be many cases where you want to ignore the marked-as-deleted clients. If so you could write the appropiate query in find(). As a nice side effect the GridView will show only the not marked-as-deleted clients automatically.

    To get the marked-as-deleted clients you would need an extra methode, of course, if this is needed at all (you could want to delete them in the db directly and you don't need php code for this). But most of the time you don't need them. So you could filter them out by overriding the find method.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错