2017 © Pedro Peláez
 

yii2-extension yii2-simple-pages

basic yii2 extension to create sites with simple set of pages

image

deitsolutions/yii2-simple-pages

basic yii2 extension to create sites with simple set of pages

  • Wednesday, July 11, 2018
  • by deitsolutions
  • Repository
  • 2 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Simple Pages Module

Simple Pages Module is a simple client-side CMS module for Yii2., (*1)

Installation

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

Configuration

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',
                    ...
            ],
            ...
        ],
    ],
    ...             
]
];

Usage example

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)

Structure of the folders:

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

File examples

[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)

URLs examples

  • Your site index page: yourhost
  • Blog page: yourhost/blog
  • Blog page for 1st post: yourhost/blog/post1.html
  • Blog page for 2st post: yourhost/blog/post2.html

An example of creating a solitary new page

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',
                ...
        ],
        ...
    ],
    ...
]
  1. create the new file /views/themes/{your-theme}/common/pages/faq.php;
  2. open the address yourhost/faq;

theme parameter

Theme parameter could be varied to enable different themes for the views, (*16)

License

Please take a look on the bundled LICENSE.md for details., (*17)

The Versions

11/07 2018

dev-master

9999999-dev https://github.com/deitsolutions/yii2-simple-pages

basic yii2 extension to create sites with simple set of pages

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 page