本文整理汇总了PHP中app\models\Author::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::findOne方法的具体用法?PHP Author::findOne怎么用?PHP Author::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Author
的用法示例。
在下文中一共展示了Author::findOne方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionDelete
/**
* Удаление автора.
*
* @param int $id
* @return \yii\web\Response
*/
public function actionDelete($id)
{
/** @var Author $modelAuthor */
$modelAuthor = Author::findOne($id);
if ($modelAuthor->delete()) {
return $this->redirect(['back-author/index']);
}
return $this->refresh();
}
示例2: _saveBook
/**
* Сохраняет модель и связанные данные
*
* @param Book $modelBook
* @return \yii\web\Response
*/
private function _saveBook(Book $modelBook)
{
$authorIds = Yii::$app->request->post('authors');
$tagIds = Yii::$app->request->post('tags');
if ($modelBook->load(Yii::$app->request->post()) && $modelBook->save()) {
array_map(function ($model) use($modelBook) {
$modelBook->unlink('authors', $model, true);
}, $modelBook->authors);
foreach ($authorIds ?: [] as $authorId) {
/** @var Author $modelAuthor */
$modelAuthor = Author::findOne($authorId);
$modelBook->link('authors', $modelAuthor);
}
array_map(function ($model) use($modelBook) {
$modelBook->unlink('tags', $model, true);
}, $modelBook->tags);
foreach ($tagIds ?: [] as $tagId) {
/** @var Tag $modelTag */
$modelTag = Tag::findOne($tagId);
$modelBook->link('tags', $modelTag);
}
return $this->redirect(['back-book/view', 'id' => $modelBook->id]);
}
}
示例3: runPKSearch
public function runPKSearch($i)
{
$author = $this->authors[array_rand($this->authors)];
$author = Author::findOne($author->id);
// $this->em->clear();
}
示例4: findModel
/**
* Finds the Author model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Author the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Author::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例5: actionView
/**
* Displays a single Book model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$model = $this->findModel($id);
return $this->render('view', ['model' => $model, 'author' => (new AuthorEntity())->createEntity(Author::findOne($model->author_id))]);
}
示例6: actionGetTags
/**
* Генератор тэговых страниц
*/
public function actionGetTags()
{
$list = scandir('/home/romanych/www/vrs/pages/');
$list = array_diff($list, ['.', '..']);
//var_dump($list); exit;
$alphabet = fopen("/home/romanych/www/vrs/alphabet.html", "w");
fwrite($alphabet, self::$header);
foreach ($list as $letter) {
fwrite($alphabet, "<div class='letters'><a href='pages/" . $letter . "/tags.html'>" . $letter . "</a></div>");
$alfa_tags = fopen("/home/romanych/www/vrs/pages/" . $letter . "/tags.html", "w");
fwrite($alfa_tags, self::$header);
fwrite($alfa_tags, self::$footer);
fclose($alfa_tags);
}
fwrite($alphabet, self::$footer);
fclose($alphabet);
$tags = Tag::find()->orderBy('name')->all();
//var_dump($tags); exit;
//$file = fopen("/home/romanych/www/vrs/tags.html", "w");
//fwrite($file, self::$header);
foreach ($tags as $tag) {
$first_letter = mb_substr($tag->name, 0, 1, 'UTF-8');
//var_dump($first_letter); exit;
$big_first_letter = mb_strtoupper($first_letter, 'UTF-8');
$alfa_tags = fopen("/home/romanych/www/vrs/pages/" . $big_first_letter . "/tags.html", "a");
fwrite($alfa_tags, "<a href='" . TranslateHelper::translit($tag->name) . ".html'><button type='button' class='btn btn-default btn-lg'>{$tag->name}</button></a>");
fwrite($alfa_tags, self::$footer);
fclose($alfa_tags);
//fwrite($file, "<p><a href='pages/".$big_first_letter."/". TranslateHelper::translit($tag->name) .".html'>$tag->name</a></p>");
$page = fopen("/home/romanych/www/vrs/pages/" . $big_first_letter . "/" . TranslateHelper::translit($tag->name) . ".html", "w");
fwrite($page, '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>.item_head{font-weight: bold;} body{padding-left: 20px; padding-top: 20px;} </style>');
$items = explode(",", $tag->items);
$r = 1;
foreach ($items as $item) {
try {
$item = Items::findOne(['id' => (int) $item]);
$source = Source::findOne(['id' => $item->source_id]);
$author = Author::findOne(['id' => $source->author_id]);
fwrite($page, "<p class='item_head'>{$r} {$item->title} ({$author->name} - {$source->title})</p>\n " . $this->renderPlayer($item->audio_link) . "\n " . nl2br("<p>{$item->text}</p>") . "\n\n ");
} catch (\ErrorException $e) {
echo $e->getMessage() . PHP_EOL;
var_dump(Items::findOne(['id' => (int) $item]));
}
$r++;
}
fwrite($page, self::$footer);
fclose($page);
}
//fwrite($file, self::$footer);
//fclose($file);
}