noumo / easyii

Easy yii2 cms powered by Yii framework 2
http://easyiicms.com
593 stars 272 forks source link

private function findItem returns wrong article #180

Open izemize opened 8 years ago

izemize commented 8 years ago

Hy

When you use "articles/view/10-elethelyzet-ami-szemuvegeskent-ismeros-lehet" or "articles/view/10" return wrong article. It's because you use OR operator in where clause with string and integer. Maybe fix this.

    private function findItem($id_slug)
    {
        if( is_int($id_slug) )
        {
            $article = Item::find()->where('item_id = :id_slug',[':id_slug'=>$id_slug])->status(Item::STATUS_ON)->one();
        }else
        {
            $article = Item::find()->where('slug=:id_slug',[':id_slug'=>$id_slug])->status(Item::STATUS_ON)->one();
        }

        //$article = Item::find()->where(['slug'=>$id_slug])->status(Item::STATUS_ON)->one();
        if($article) {
            $article->updateCounters(['views' => 1]);
            return new ArticleObject($article);
        } else {
            return null;
        }
    }