本文整理汇总了PHP中app\models\Article::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::findOne方法的具体用法?PHP Article::findOne怎么用?PHP Article::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Article
的用法示例。
在下文中一共展示了Article::findOne方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findModel
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundException("The requested page does not exist");
}
}
示例2: actionView
public function actionView($id)
{
$counter = new counter();
$counter->hitsCounter('site/view', $id);
$model = Article::findOne(['id' => $id]);
$article = new Article();
return $this->render('view', ['model' => $model, 'article' => $article]);
}
示例3: findModel
/**
* Finds the Article model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return Article the loaded model
*/
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
return false;
}
}
示例4: actionShowwidget
public function actionShowwidget($post)
{
$model = new Article();
$ress = $model->findOne(['id' => $post])->toArray();
// получаем статью детально ввиде массива
//$CatRess = $model2->findOne(['id' => $ress['category_id']]); // Это я так баловался:)
$CatRess = $model->LoadCat($ress['category_id']);
//Загружаем из модели категорию с полученым ID, вытащить напрямую без указания не получилось
return $this->render('views', ['modelcat' => $CatRess, 'model' => $ress]);
}
示例5: actionDelete
public function actionDelete($id = null)
{
if ($id === null) {
Yii::$app->session->setFlash('PostDeletedError');
Yii::$app->getResponse()->redirect(array('article/index'));
}
/** @var Article $article */
$article = Article::findOne($id);
if ($article === null) {
Yii::$app->session->setFlash('PostDeletedError');
Yii::$app->getResponse()->redirect(array('article/index'));
}
$article->delete();
Yii::$app->session->setFlash('PostDeleted');
Yii::$app->getResponse()->redirect(array('article/index'));
}
示例6: order
private function order($id = null, $ordering = null, $direction = null)
{
if ($id != null || $ordering != null || $direction != null) {
$sess = Yii::$app->session->get('sessArticle');
if ($direction == "up") {
$newSortOrder = $ordering - 1;
} else {
if ($direction == "down") {
$newSortOrder = $ordering + 1;
}
}
$parent = Article::findOne($id);
$where = array();
$where[] = "ordering = '{$newSortOrder}'";
$where[] = "langs = '" . $parent->langs . "'";
$where[] = "cid = '" . $parent->cid . "'";
$connection = Yii::$app->db;
$sql = "SELECT id FROM tbl_article " . (count($where) ? "\n WHERE " . implode(' AND ', $where) : '');
$command = $connection->createCommand($sql);
$reader = $command->query();
foreach ($reader as $row) {
$otherId = $row["id"];
}
$where = array();
$where[] = "id = '{$id}'";
$where[] = "langs = '" . $parent->langs . "'";
$where[] = "cid = '" . $parent->cid . "'";
$sql = 'UPDATE tbl_article SET ordering = "' . $newSortOrder . '" ' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : '');
$command = $connection->createCommand($sql);
$command->execute();
if ($reader->getRowCount() > 0) {
$where = array();
$where[] = "id = '{$otherId}'";
$where[] = "langs = '" . $parent->langs . "'";
$where[] = "cid = '" . $parent->cid . "'";
$sql = 'UPDATE tbl_article SET ordering = "' . $ordering . '"' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : '');
$command = $connection->createCommand($sql);
$command->execute();
}
return $this->redirect(['index', 'page' => $_REQUEST['page']]);
}
}
示例7: checkOwner
public function checkOwner($id)
{
$auth = \Yii::$app->authManager->getAssignments(\Yii::$app->user->id);
//print_r($auth);
$access = false;
if ($auth['Editor']->roleName == 'Editor') {
$model = Article::findOne($id);
if ($model->createBy == \Yii::$app->user->id) {
$access = true;
}
} else {
$access = true;
}
return $access;
}
示例8: findModel
/**
* Finds the Article model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Article the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
$this->layout = 'admin';
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例9: findModel
/**
* Finds the Article model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Article the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
public static function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}