Skip to content

Commit 4471376

Browse files
committed
+ notFound page
1 parent 1f862c1 commit 4471376

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/controllers/SiteController.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ public function actionContact()
4646

4747
public function actionSearch($query)
4848
{
49-
$package = $this->getAssetPackage($query);
50-
$params = ['package' => $package, 'query' => $query, 'forceUpdate' => false];
49+
try {
50+
$package = $this->getAssetPackage($query);
51+
$params = ['package' => $package, 'query' => $query, 'forceUpdate' => false];
52+
53+
if ($package->canAutoUpdate()) {
54+
$params['forceUpdate'] = true;
55+
}
56+
} catch (\Exception $e) {
57+
$query = strtolower(preg_replace('/[^a-z0-9-]/i', '', $query));
5158

52-
if ($package->canAutoUpdate()) {
53-
$params['forceUpdate'] = true;
59+
return $this->render('notFound', compact('query'));
5460
}
5561

5662
return $this->render('search', $params);

src/views/site/notFound.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* @var $this yii\web\View
5+
* @var string $query the search query that was submitted
6+
* @var \hiqdev\assetpackagist\models\AssetPackage $package
7+
* @var bool $forceUpdate Whether the application must force package update
8+
*/
9+
10+
use yii\helpers\Html;
11+
use yii\helpers\Inflector;
12+
use yii\helpers\Json;
13+
use yii\helpers\Url;
14+
15+
$this->title = 'Not found';
16+
$this->params['searchQuery'] = $query;
17+
18+
?>
19+
20+
<div class="package-details">
21+
<h1>
22+
<?= $this->title ?>
23+
</h1>
24+
<h1>
25+
<small class="repository-link">
26+
Please use: <a href="/site/search?query=bower-asset/<?= $query ?>">bower-asset/<?= $query ?></a> or
27+
<a href="/site/search?query=npm-asset/<?= $query ?>">npm-asset/<?= $query ?></a>
28+
</small>
29+
</h1>
30+
</div>

0 commit comments

Comments
 (0)