Giter VIP home page Giter VIP logo

yii2-pages's Introduction

yii2-pages

Latest Stable Version Total Downloads Latest Unstable Version License Build Status Coverage Status

A static pages module implements CRUD using Imperavi Redactor.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist bupy7/yii2-pages "*"

or add

"bupy7/yii2-pages": "*"

to the require section of your composer.json file.

Installation

Add module in your config file:

'bootstrap' => ['pages'],

...

'modules' => [
    ...

    'pages' => 'bupy7\pages\Module',
]

You must add the above config in your console config file to apply migrations.

By default module uses table name '{{%page}}'. If in your database this table is exist - change it adding to configuration of module new table name:

'modules' => [
    ...

    'pages' => [
        'class' => 'bupy7\pages\Module',
        'tableName' => '{{%your_table_name}}',
    ],
]

Run migration

./yii migrate/up --migrationPath=@bupy7/pages/migrations

Without module in console config file this command will throw an exception.

Usage

In module two controllers: default and manager.

manager need for control the pages out of the control panel. You need protect it controller via controllerMap or override it for add behavior with AccessControl.

Example:

'modules' => [
    ...

    'pages' => [
        'class' => 'bupy7\pages\Module',
        
        ...

        'controllerMap' => [
            'manager' => [
                'class' => 'bupy7\pages\controllers\ManagerController',
                'as access' => [
                    'class' => AccessControl::className(),
                    'rules' => [
                        [
                            'allow' => true,
                            'roles' => ['admin'],
                        ],
                    ],
                ],
            ],
        ],
    ],
],

default for display of pages to site. You need add url rules to file of config for getting content via aliases pages.

Example:

'urlManager' => [
    'rules' => [
        ...

        'pages/<page:[\w-]+>' => 'pages/default/index',
    ],
],

You can upload and add files/images via Imperavi Redactor, if enable it:

'modules' => [
    ...
    
    'pages' => [
        'class' => 'bupy7\pages\Module',
        
        ...

        'pathToImages' => '@webroot/images',
        'urlToImages' => '@web/images',
        'pathToFiles' => '@webroot/files',
        'urlToFiles' => '@web/files',
        'uploadImage' => true,
        'uploadFile' => true,
        'addImage' => true,
        'addFile' => true,
    ],
],

Set up the custom language at Imperavi redactor:

'modules' => [
    ...

    'pages' => [
        'class' => 'bupy7\pages\Module',
        'imperaviLanguage' => 'es',
    ],
]

There is all list a languages here: /vendor/vova07/yii2-imperavi-widget/src/assets/lang.

License

yii2-pages is released under the BSD 3-Clause License.

yii2-pages's People

Contributors

almix avatar bupy7 avatar i-panov avatar maxxer avatar xaerobiont avatar zacksleo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yii2-pages's Issues

Allow model customization

It would be great if it could be possible to customize the model. For example, I'd like to add a language field to the page, in order to be able to show different content for different languages.

Url in custom layout

I'm using my layout. It has a reference to Url::to(['profile/index']) which should look like this: /profile/index, but instead it looks like this: /pages/profile/index when I use pages manager (on the remaining pages the links are correct). Why is this happening?

Migration failed

Total 2 new migrations to be applied:
        m150429_155009_create_page_table
        m180927_200917_add_display_title

*** applying m150429_155009_create_page_table
    > create table {{%pages}} ... done (time: 0.151s)
    > create unique index pages_idx_1 on {{%pages}} (alias) ... done (time: 0.091s)
    > create index pages_idx_2 on {{%pages}} (alias,published) ... done (time: 0.132s)
*** applied m150429_155009_create_page_table (time: 0.392s)

*** applying m180927_200917_add_display_title
    > add column display_title boolean DEFAULT 1 to table {{%pages}} ... done (time: 0.261s)
Exception: SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT LEVEL1 does not exist
The SQL being executed was: RELEASE SAVEPOINT LEVEL1 (\vendor\yiisoft\yii2\db\Schema.php:664)
#0 \vendor\yiisoft\yii2\db\Command.php(1295): yii\db\Schema->convertException(Object(PDOException), 'RELEASE SAVEPOI...')
#1 \vendor\yiisoft\yii2\db\Command.php(1091): yii\db\Command->internalExecute('RELEASE SAVEPOI...')
#2 \vendor\yiisoft\yii2\db\Schema.php(398): yii\db\Command->execute()
#3 \vendor\yiisoft\yii2\db\Transaction.php(172): yii\db\Schema->releaseSavepoint('LEVEL1')
#4 \vendor\yiisoft\yii2\db\Migration.php(118): yii\db\Transaction->commit()
#5 \vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(725): yii\db\Migration->up()
#6 \vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(199): yii\console\controllers\BaseMigrateController->migrateUp('m180927_200917_...')
#7 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#8 \vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#9 \vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 \vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction('up', Array)
#11 \vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('up', Array)
#12 \vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate/up', Array)
#13 \migrations\m180425_074410_init.php(37): yii\console\Application->runAction('migrate/up', Array)
#14 \vendor\yiisoft\yii2\db\Migration.php(114): m180425_074410_init->safeUp()
#15 \vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(725): yii\db\Migration->up()
#16 \vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(199): yii\console\controllers\BaseMigrateController->migrateUp('m180425_074410_...')
#17 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(1)
#18 \vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#19 \vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#20 \vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction('up', Array)
#21 \vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('up', Array)
#22 \vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate/up', Array)
#23 \vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate/up', Array)
#24 \vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#25 \yii(20): yii\base\Application->run()
#26 {main}
*** failed to apply m180927_200917_add_display_title (time: 0.273s)


1 from 2 migration was applied.

Add button for linking internal page

It would be great to have another link button in the toolbar to link an internal page. An user should be asked for page title or alias, and the resulting url should be automatically generated.

Migrate failed

error migrate: need insert initialization module in console config, or else Yii::$app->getModule('pages') return NULL and tableName is not found.

Do not display the page title

Please add the setting in the config or in the model so that you can not display the page title. I'm using my layout and there I already have the page title. Because of this, duplication is obtained.

Migration default value wrong for PostgresSQL

The code below in m150429_155009_create_page_table.php will cause error when run with PostgreSQL
'published' => Schema::TYPE_BOOLEAN . ' DEFAULT 1',
The bug fix as below will work for MySQL, PostgreSQL, SQLite (I've tested).
'published' => Schema::TYPE_BOOLEAN . ' DEFAULT TRUE',

'published' => Schema::TYPE_BOOLEAN . ' DEFAULT 1',

The same issue in m180927_200917_add_display_title.php
Current code
$this->addColumn($this->_tableName, 'display_title', Schema::TYPE_BOOLEAN . ' DEFAULT 1');
should be changed to
$this->addColumn($this->_tableName, 'display_title', Schema::TYPE_BOOLEAN . ' DEFAULT TRUE');

$this->addColumn($this->_tableName, 'display_title', Schema::TYPE_BOOLEAN . ' DEFAULT 1');

AccessControl as config in README.md not work

Issue description

Config pages/manager as the description in README.md, but it does not filter the user for pages/manager. Guess user can access to pages/manager.

Steps to reproduce the issue

  1. Access to pages/manager/index

What's the expected result?

  • Redirect to login page.

What's the actual result?

  • The list of pages is displayed.

Additional details / screenshot

  • notlogin

Impervi

followed all settings in config, yet Impervi outputs "true" in Add File/Picture upload box
screen shot 2018-05-20 at 12 46 42 am

Migration fail: Invalid default value for 'created_at'

php 7.0.8 x64
mysql 5.7.11 x64
windows 8.1 x64

Setting 0 or "0000-00-00" does not help

$ ./yii migrate
Yii Migration Tool (based on Yii v2.0.10-dev)

Total 1 new migration to be applied:
        m150429_155009_create_page_table

Apply the above migration? (yes|no) [no]:y
*** applying m150429_155009_create_page_table
    > create table {{%page}} ...Exception 'yii\db\Exception' with message 'SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at'
The SQL being executed was: CREATE TABLE `page` (
        `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
        `title` varchar(255) NOT NULL,
        `alias` varchar(255) NOT NULL,
        `published` tinyint(1) DEFAULT 1,
        `content` text,
        `title_browser` varchar(255),
        `meta_keywords` varchar(200),
        `meta_description` varchar(160),
        `created_at` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00",
        `updated_at` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00"
)'

in C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\db\Schema.php:631

Error Info:
Array
(
    [0] => 42000
    [1] => 1067
    [2] => Invalid default value for 'created_at'
)

Stack trace:
#0 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\db\Command.php(854): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLE `p...')
#1 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\db\Migration.php(261): yii\db\Command->execute()
#2 C:\Tools\OpenServer\domains\yii2-app-advanced\console\migrations\m150429_155009_create_page_table.php(35): yii\db\Migration->createTable('{{%page}}', Array)
#3 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(651): m150429_155009_create_page_table->up()
#4 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(163): yii\console\controllers\BaseMigrateController->migrateUp('m150429_155009_
...')
#5 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#6 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
#7 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#8 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\Controller.php(127): yii\base\Controller->runAction('', Array)
#9 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\Module.php(454): yii\console\Controller->runAction('', Array)
#10 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
#11 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
#12 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))
#13 C:\Tools\OpenServer\domains\yii2-app-advanced\yii(27): yii\base\Application->run()
#14 {main}

....
Finally I got it working by using DEFAULT CURRENT_TIMESTAMP for created_at and DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP for updated_at.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.