获取文章的点赞数和浏览数

@param $id
@return array
@throws NotFoundHttpException
971017
public function actionViewAjax($id)
    {
        $model = Article::findOne($id);
        if( $model === null ) throw new NotFoundHttpException("None exists article id");
        return [
            'likeCount' => (int)$model->getArticleLikeCount(),
            'scanCount' => $model->scan_count * 100,
            'commentCount' => $model->comment_count,
        ];
    }
454105
public function read($id) {
        $this->Model->id = $id;

        $result = $this->AdminToolbar->getRecordById($this->Model, $id);

        if (!$result) {
            throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName));
        }

        $item_id = $result['ItemReport']['foreign_key'];
        $itemModel = Admin::introspectModel($result['ItemReport']['model']);
        $itemResult = $this->AdminToolbar->getRecordById($itemModel, $item_id);

        if ($this->request->is('post')) {
            $action = $this->request->data['ItemReport']['report_action'];
            $status = ItemReport::RESOLVED;
            $messages = array();
            $title = $itemResult[$itemModel->alias][$itemModel->displayField];

            // Mark report as invalid
            if ($action === 'invalid_report') {
                $status = ItemReport::INVALID;

            // Delete the item
            } else if ($action === 'delete_item') {
                if ($this->AdminToolbar->hasAccess($itemModel, 'delete') && $itemModel->delete($item_id, true)) {
                    $messages[] = __d('admin', 'Successfully deleted %s with ID %s', array($itemModel->singularName, $item_id));
                    $this->AdminToolbar->logAction(ActionLog::DELETE, $itemModel, $item_id, __d('admin', 'Via item report #%s', $id), $title);
                }

            // Custom item callback
            } else if (method_exists($itemModel, $action)) {
                if ($itemModel->{$action}($item_id)) {
                    $messages[] = __d('admin', 'Triggered %s.%s() process', array($itemModel->alias, $action));
                    $this->AdminToolbar->logAction(ActionLog::UPDATE, $itemModel, $item_id, __d('admin', '%s.%s() via item report #%s', array($itemModel->alias, $action, $id)), $title);
                }

            } else {
                throw new BadRequestException(__d('admin', 'Invalid Report Action'));
            }

            $comment = __d('admin', 'Changed report status to %s', $this->Model->enum('status', $status));
            $messages[] = $comment;

            $this->Model->markAs($id, $status, $this->Auth->user('id'), $this->request->data['ItemReport']['log_comment']);
            $this->AdminToolbar->logAction(ActionLog::UPDATE, $this->Model, $id, $comment);

            // Set message
            $this->AdminToolbar->setFlashMessage(implode('; ', $messages));
            $this->redirect(array('action' => 'index'));

        } else {
            $this->Model->set($result);
            $this->AdminToolbar->logAction(ActionLog::READ, $this->Model, $id);
        }

        $this->set('result', $result);
        $this->set('item', $itemResult);
    }
307397
protected function findModel($id)
    {
        $query = Fans::find()
            ->andWhere([
                'id' => $id,
                'wid' => $this->getWechat()->id
            ]);
        if (($model = $query->one()) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
382800
public function getDepartmentList($id = null)
    {
        $result = $this->httpGet(self::WECHAT_DEPARTMENT_LIST, [
            'access_token' => $this->getAccessToken(),
        ] + ($id === null ? [] : [
            'id' => $id
        ]));
        // $this->dump($result);die();
        return isset($result['errmsg']) && $result['errmsg'] == 'ok' ? $result['department'] : $this->dump($result);
    }
1027593
protected function getValue($id)
    {
        $file = $this->getFile($id);
        if (!file_exists($file)) {
            return null;
        }
        if (filemtime($file) < time()) { // filemtime : 文件最后修改时间
            @unlink($file);
            return null;
        }
        return file_get_contents($file);
    }
268285
public function getArticleById(string $id): Generator
    {
        yield from $this->sendCommand(new Command('ARTICLE', $id));

        $data = yield from $this->encoder->readData($this->stream);
        return Article::parse($data);
    }
673428
public function raw(string $id)
    {
        $id = $this->getRealId($id);

        if (array_key_exists($id, $this->definitions)) {
            return $this->definitions[$id];
        }

        throw new Exception\NotFoundException($id);
    }
694280
public function getContentTags($id)
    {
        $items = array();
        $tags = Content::model()->findByPk($id)->getTags();
        foreach ($tags as $item)
            $items[] = array('label' => $item, 'url' => Yii::app()->createUrl('/search?q=' . $item));

        return $items;
    }
984103
protected function getAddress($id)
    {
        $address = $this->addressManager->findOneBy(['id' => $id]);

        if (null === $address) {
            throw new NotFoundHttpException(sprintf('Address (%d) not found', $id));
        }

        return $address;
    }
784994
protected function findModel($id)
    {
        $user = Page::findOne($id);
        if ($user === null) {
            throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist'));
        }
        return $user;
    }
44731
protected function findModel($id)
    {
        $item = Yii::$app->authManager->getRule($id);
        if ($item) {
            return new BizRule($item);
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
461656
public function find($id)
    {
        try
        {
            $model = $this->model->findOrFail($id);
        }
        catch(ModelNotFoundException $e)
        {
            throw new NotFoundException;
        }

        return $model;
    }
390868
protected function getInvoice($id)
    {
        $invoice = $this->invoiceManager->findOneBy(['id' => $id]);

        if (null === $invoice) {
            throw new NotFoundHttpException(sprintf('Invoice (%d) not found', $id));
        }

        return $invoice;
    }
1351711
protected function findModel($id)
    {
        if (($model = Contact::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
        }
    }
1147250
public function loadUrlAlias($id)
    {
        list($parentId, $textMD5) = explode('-', $id);
        $data = $this->gateway->loadRow($parentId, $textMD5);

        if (empty($data)) {
            throw new NotFoundException('URLAlias', $id);
        }

        $data['raw_path_data'] = $this->gateway->loadPathData($data['id']);

        return $this->mapper->extractUrlAliasFromData($data);
    }
692805
public function index($id)
    {
        $this->authorize('readList', Content::class);
        $input   = $this->validator->validate('list');
        $params  = $this->processor->process($input)->getProcessedFields();
        $content = $this->repository->getById($id);
        if (!empty($content)) {
            $results = $this->repository->getTranslations(
                $content,
                $params['filter'],
                $params['orderBy'],
                $params['page'],
                $params['perPage']
            );
            return $this->respondWithSuccess($results, new ContentTranslationTransformer);
        } else {
            return $this->respondNotFound();
        }
    }
1141628
protected function getOrder($id)
    {
        $order = $this->orderManager->findOneBy(['id' => $id]);

        if (null === $order) {
            throw new NotFoundHttpException(sprintf('Order (%d) not found', $id));
        }

        return $order;
    }