{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/3665","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/3665/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/3665/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/3665/events","html_url":"https://github.com/yiisoft/yii2/issues/3665","id":34742073,"number":3665,"title":"Gii: suggest for ModelSearch","user":{"login":"mdmunir","id":5828252,"avatar_url":"https://avatars.githubusercontent.com/u/5828252?v=3","gravatar_id":"","url":"https://api.github.com/users/mdmunir","html_url":"https://github.com/mdmunir","followers_url":"https://api.github.com/users/mdmunir/followers","following_url":"https://api.github.com/users/mdmunir/following{/other_user}","gists_url":"https://api.github.com/users/mdmunir/gists{/gist_id}","starred_url":"https://api.github.com/users/mdmunir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdmunir/subscriptions","organizations_url":"https://api.github.com/users/mdmunir/orgs","repos_url":"https://api.github.com/users/mdmunir/repos","events_url":"https://api.github.com/users/mdmunir/events{/privacy}","received_events_url":"https://api.github.com/users/mdmunir/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/feature%3Agii","name":"feature:gii","color":"bfd4f2"}],"state":"closed","locked":false,"assignee":{"login":"samdark","id":47294,"avatar_url":"https://avatars.githubusercontent.com/u/47294?v=3","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/yiisoft/yii2/milestones/8","labels_url":"https://api.github.com/repos/yiisoft/yii2/milestones/8/labels","id":823739,"number":8,"title":"2.0.2","description":"","creator":{"login":"qiangxue","id":993322,"avatar_url":"https://avatars.githubusercontent.com/u/993322?v=3","gravatar_id":"","url":"https://api.github.com/users/qiangxue","html_url":"https://github.com/qiangxue","followers_url":"https://api.github.com/users/qiangxue/followers","following_url":"https://api.github.com/users/qiangxue/following{/other_user}","gists_url":"https://api.github.com/users/qiangxue/gists{/gist_id}","starred_url":"https://api.github.com/users/qiangxue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiangxue/subscriptions","organizations_url":"https://api.github.com/users/qiangxue/orgs","repos_url":"https://api.github.com/users/qiangxue/repos","events_url":"https://api.github.com/users/qiangxue/events{/privacy}","received_events_url":"https://api.github.com/users/qiangxue/received_events","type":"User","site_admin":false},"open_issues":35,"closed_issues":137,"state":"open","created_at":"2014-10-13T11:20:19Z","updated_at":"2015-01-07T11:13:37Z","due_on":"2015-01-11T05:00:00Z","closed_at":null},"comments":28,"created_at":"2014-06-02T01:54:58Z","updated_at":"2015-01-07T12:30:35Z","closed_at":"2015-01-06T16:03:30Z","body":"Non critical issue.\r\nIn method `ModelSearch::search()` generated by gii. we get code like this\r\n```php\r\nif (!($this->load($params) && $this->validate())) {\r\n    return $dataProvider;\r\n }\r\n```\r\nit's better if we change with\r\n```php\r\n$this->load($params);\r\nif (!$this->validate()) {\r\n    return $dataProvider;\r\n}\r\n```\r\nWhat goal of this issue is, sometimes we need to open page index with initial filter. E.g. at first time, the page just showing opened order. For now, i do like this:\r\n```php\r\n// in actionIndex()\r\n$searchModel = new OrderSearch();\r\n$formName = OrderSearch::formName();\r\n$params = ArrayHelper::merge([\r\n    $formName=>['status'=>Order::STATUS_OPEN]\r\n],Yii::$app->request->getQueryParams());\r\n$dataProvider = $searchModel->search($params);\r\n```\r\nWith this sugget, we just do like this:\r\n```php\r\n$searchModel = new OrderSearch(['status'=>Order::STATUS_OPEN]);\r\n$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/69015710","html_url":"https://github.com/yiisoft/yii2/issues/3665#issuecomment-69015710","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/3665","id":69015710,"user":{"login":"fsateler","id":1322013,"avatar_url":"https://avatars.githubusercontent.com/u/1322013?v=3","gravatar_id":"","url":"https://api.github.com/users/fsateler","html_url":"https://github.com/fsateler","followers_url":"https://api.github.com/users/fsateler/followers","following_url":"https://api.github.com/users/fsateler/following{/other_user}","gists_url":"https://api.github.com/users/fsateler/gists{/gist_id}","starred_url":"https://api.github.com/users/fsateler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsateler/subscriptions","organizations_url":"https://api.github.com/users/fsateler/orgs","repos_url":"https://api.github.com/users/fsateler/repos","events_url":"https://api.github.com/users/fsateler/events{/privacy}","received_events_url":"https://api.github.com/users/fsateler/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T12:30:35Z","updated_at":"2015-01-07T12:30:35Z","body":"On Tue, Jan 6, 2015 at 11:08 PM, Hafid Mukhlasin <notifications@github.com>\nwrote:\n\n> Please give me reason why this is be revert.. hem :(\n\n\nBecause it was cited as a valid use case to: (a) create search models with\nuntrusted data without using `load()` and/or (b) set defaults via  the\n`default` validator. And yet, the revert does neither.\n\nI will note that the original (and current) implementation, it is very very\nawkward to set a default for a search parameter.\n\nPlease revert the revert. It helps noone:\n\n1. People who do not use defaults: indifferent between the reverted and the\noriginal versions, both work.\n2. People who use defaults with trusted data: better with the reverted\nversion than the original.\n3. People who use defaults via the `default` validator: indifferent between\nthe reverted and original versions, neither works.\n4. People who use defaults with untrusted data: indifferent between the\nversions, as neither will validate the original untrusted data.\n\nI would actively argue against usecase (a). There is a reason why there is\na `load()` method: to load untrusted values. If you feed untrusted data to\na model constructor, then you get to keep the pieces.\n\n-- \n\nSaludos,\nFelipe Sateler"}}