|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hiqdev\yii2\modules\pages\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use hiqdev\yii2\modules\pages\models\AbstractPage; |
|
6
|
|
|
use hiqdev\yii2\modules\pages\models\PagesIndex; |
|
7
|
|
|
use Yii; |
|
8
|
|
|
use yii\helpers\Html; |
|
9
|
|
|
use yii\web\NotFoundHttpException; |
|
10
|
|
|
use yii\base\InvalidConfigException; |
|
11
|
|
|
|
|
12
|
|
|
class RenderController extends \yii\web\Controller |
|
13
|
|
|
{ |
|
14
|
|
|
public function getViewPath() |
|
15
|
|
|
{ |
|
16
|
|
|
return Yii::$app->getViewPath(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Index action. |
|
21
|
|
|
* @param string $page |
|
22
|
|
|
* @return string rendered page |
|
23
|
|
|
*/ |
|
24
|
|
|
public function actionIndex($page = null) |
|
25
|
|
|
{ |
|
26
|
|
|
if (!$page) { |
|
|
|
|
|
|
27
|
|
|
$page = 'index'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$path = $this->module->find($page); |
|
31
|
|
|
|
|
32
|
|
|
if ($path === null) { |
|
33
|
|
|
throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$meta = $this->module->getMetadata($page); |
|
37
|
|
|
|
|
38
|
|
|
if ($meta['type'] === 'dir') { |
|
39
|
|
|
$index = PagesIndex::createFromDir($path); |
|
40
|
|
|
|
|
41
|
|
|
return $this->render('@hiqdev/com/views/site/index', ['dataProvider' => $index->getDataProvider()]); |
|
42
|
|
|
} else { |
|
43
|
|
|
$page = AbstractPage::createFromFile($path); |
|
44
|
|
|
|
|
45
|
|
|
return $this->renderPage($page); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function renderPhp($path) |
|
50
|
|
|
{ |
|
51
|
|
|
$content = $this->renderFile($this->module->localPath($path)); |
|
52
|
|
|
return $this->renderContent($content); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function renderPage($page, array $params = []) |
|
56
|
|
|
{ |
|
57
|
|
|
if ($page->layout) { |
|
58
|
|
|
$this->layout = $page->layout; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if ($page->title) { |
|
62
|
|
|
$this->view->title = Html::encode($page->title); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->view->params = $page->getData(); |
|
66
|
|
|
|
|
67
|
|
|
return $this->renderContent($page->render($params)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: