本文整理汇总了PHP中app\models\Authors::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Authors::findOne方法的具体用法?PHP Authors::findOne怎么用?PHP Authors::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Authors
的用法示例。
在下文中一共展示了Authors::findOne方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionView
/**
* Displays a single Books model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$book = $this->findModel($id)->attributes;
$author = Authors::findOne($book["author_id"]);
$book["author"] = $author->attributes;
header('Content-Type: application/json');
echo json_encode($book, JSON_UNESCAPED_UNICODE);
/*
echo $book->name;
echo $book->date_create;
echo $book->date_update;
echo $book->preview;
*/
}
示例2: findModel
/**
* Finds the Authors model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Authors the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Authors::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例3: getimagesize
echo Html::encode($this->title);
?>
</h1>
<p>
<?php
echo Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
<?php
echo Html::a('Удалить', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Вы уверены, что хотите удалить книгу?', 'method' => 'post']]);
?>
</p>
<?php
$attributes = ['name', 'date_create', 'date_update'];
if (!empty($model->preview)) {
$path = Yii::getAlias('@webroot' . $model->preview);
if (file_exists($path)) {
$size = getimagesize($path);
$attributes[] = ['attribute' => 'preview', 'format' => 'raw', 'value' => Html::a(Html::img($model->preview, ['width' => $size[0], 'height' => $size[1]]), str_replace('preview', 'images', $model->preview), ['rel' => 'fancybox'])];
}
}
$author = Authors::findOne($model->author_id);
$attributes = array_merge($attributes, ['date', ['attribute' => 'author_id', 'format' => 'raw', 'value' => $author->firstname . ' ' . $author->lastname]]);
echo DetailView::widget(['model' => $model, 'attributes' => $attributes]);
?>
</div>