dev-master
9999999-dev https://github.com/deitsolutions/yii2-simple-pagesbasic yii2 extension to create sites with simple set of pages
BSD-3-Clause
The Requires
- php >=5.5.0
- yiisoft/yii2 *
yii2 page
basic yii2 extension to create sites with simple set of pages
Simple Pages Module is a simple client-side CMS module for Yii2., (*1)
The preferred way to install this extension is through composer., (*2)
Place composer.phar file in the same directory with composer.json file and run, (*3)
$ php composer.phar require almeyda/yii2-simple-pages "*"
or add, (*4)
{ ... "require": { ... "almeyda/yii2-simple-pages": "*" ... } ... }
to the "require" section of your composer.json
file and run, (*5)
$ php composer.phar update
Once the extension is installed, modify your application configuration to include:, (*6)
return [ ... 'modules' => [ ... 'pages' => [ 'class' => 'almeyda\pages\Module', ], ... ], ... 'components' => [ ... 'urlManager' => [ 'class' => 'codemix\localeurls\UrlManager', 'rules' => [ ... ... ... 'pages' => [ 'pattern' => 'blog/<view>', 'route' => 'pages/page/page', 'defaults' => ['view' => 'index'], 'suffix' => '.html' ], ... ] ... ], 'view' => [ ... 'theme' => [ 'pathMap' => [ '@app/views/layouts' => '@app/views/themes/{your-theme}/layouts', '@almeyda/pages/views/page/pages/blog' => '@app/views/themes/{your-theme}/pages', ... ], ... ], ], ... ] ];
We build a very simple blog with common layout, list of posts at the index.php page and articles (like post1.php, post2.php, ...) We use example with 'blog' based on Yii2 path map feature. Please note that rule 'pages' should be added at the end of the rules stack. Otherwise all simple requests will be processed by the 'pages' module., (*7)
views/ (folder) basic yii2 project views folder └─themes/ (folder) folder with the list of themes └─{your-theme}/ (folder) your theme ├─layout/ (folder) layouts used for blog │ └main.php (file) layout html/php └─pages/ (folder) views used for blog ├─ index.php (file) file with the list of posts ├─ post1.php (file) file with some content of the 1st post └─ post2.php (file) file with some content of the 2nd post
[main.php], (*8)
layout used, (*9)
beginPage() ?> <!DOCTYPE html> <html lang="<?= Yii::$app->language ?>"> <head> <meta charset="<?= Yii::$app->charset ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?= Html::csrfMetaTags() ?> <title><?= Html::encode($this->title) ?></title> <?php $this->head() ?> </head> <body> beginBody() ?> = $content ?> endBody() ?> </body> </html> endPage() ?>
[index.php] file with the business logic, that shows the list of posts in a blog, (*10)
title = 'Title of a blog page' ?> registerMetaTag(['name' => 'description', 'content' => 'some useful content for SEO']); ?> ]*>(.*?)(.&?)>#i', $fileContent, $matches); $post['url'] = '/blog/' . substr($fileName, 0, -4) . '.html'; $post[$id] = strip_tags(@$matches[2]); } if ($post['title'] || $post['description']) { $posts[] = $post; } } } # next step we form the list of files in the current directory $provider = new \yii\data\ArrayDataProvider([ 'allModels' => $posts, 'pagination' => [ 'pageSize' => 10, ], 'sort' => [ 'attributes' => ['title', 'description'], ], ]); # next step we show the list of posts in the same html-blocks foreach ($provider->getModels() as $post) : ?> <div class="row"> <p><a HREF="<?= $post['url'] ?>" class="post-heading"><?= $post['title'] ?></a></p> <p><?= $post['description'] ?></p> <a HREF="<?= $post['url'] ?>" target="_self">Read More</a> </div> # next step we show the pagination if nessesary= \yii\widgets\LinkPager::widget(['pagination' => $provider->getPagination(),]);?>
[post1.php] Example file with some content for the 1st post, (*11)
title = 'Title of the 1st blog post' ?> registerMetaTag(['name' =>'description','content' =>'some useful content for SEO optimization' ]); ?>html-content of 1st blog page, (*12)
[post2.php] Example file with some content for the 2nd post, (*13)
title = 'Title of the 2nd blog post' ?> registerMetaTag(['name' =>'description','content' =>'some useful content for SEO optimization' ]); ?>html-content of 2nd blog page, (*14)
yourhost
yourhost/blog
yourhost/blog/post1.html
yourhost/blog/post2.html
You could follow the next guide if you want to create page with address yourhost/faq
with standard layout:
1. Ensure correct theme 'pathMap' used for component section of the config file:, (*15)
'components' => [ ... 'view' => [ ... 'theme' => [ 'pathMap' => [ '@almeyda/pages/views/page/pages' => '@app/views/themes/{your-theme}/common/pages', ... ], ... ], ... ]
/views/themes/{your-theme}/common/pages/faq.php
;yourhost/faq
;Theme parameter could be varied to enable different themes for the views, (*16)
Please take a look on the bundled LICENSE.md for details., (*17)
basic yii2 extension to create sites with simple set of pages
BSD-3-Clause
yii2 page