Search by

sy / bootstrap-cms

syone

Plugin for adding CMS feature


README

sy/bootstrap plugin for adding "CMS" feature in your sy/project based application.

Installation

From your sy/project application directory:

composer require sy/bootstrap-cms

The project's post-update-cmd hook then runs @sy install (sy/project 8.0.0, sy/bootstrap ≥ 2.2):

  1. templates/ — missing files only, so a template the project has edited is never overwritten;
  2. flyway repair then migrate — on the core schema and on the plugin schema (flyway_cms_history), straight from the package's sql/ directory.

The package ships no assets and no stylesheet, and its translations are loaded from its own directory: nothing is copied into assets/, protected/scss or protected/lang.

composer install-plugin no longer exists (sy/project 8.0.0). On a project older than that, run composer sy install after the composer require.

Page methods

Create a method in your Project\Application\Page class (in protected/src/Application/Page.php):

	/**
	 * Content page
	 */
	public function contentAction() {
		$this->setContentVars([
			'CONTENT' => new \Sy\Bootstrap\Component\Cms\Content($this->get('id', 1)),
		]);
	}

Optionally, override the home page with the content page

	/**
	 * Home page
	 */
	public function homeAction() {
		$this->copy('content');
	}

Add URL converter in Application.php

In protected/src/Application.php

<?php
namespace Project;

use Sy\Bootstrap\Lib\Url;

class Application extends \Sy\Bootstrap\Application {

	protected function initUrlConverter() {
		Url\AliasManager::setAliasFile(__DIR__ . '/../conf/alias.php');
		Url::addConverter(new Url\AliasConverter());
		Url::addConverter(new Url\ContentConverter()); // Add the content URL converter
		Url::addConverter(new Url\ControllerActionConverter());
	}

}

Converters are evaluated in registration order. ContentConverter uses an empty prefix by default, so it checks every root-level path against the content aliases: it must be registered after more specific converters and before ControllerActionConverter, which is the terminal fallback. A content is then reachable as /<alias> or /<lang>/<alias> and is mapped to p=page, a=content, id=<id>.

See the URL Converters wiki page for the full converter contract, ordering rules and Url::build() examples.

Add the content pages sitemap in Sitemap.php

In protected/src/Application/Sitemap.php

<?php
namespace Project\Application;

class Sitemap extends \Sy\Bootstrap\Application\Sitemap {

	public function __construct() {
		parent::__construct();
		$this->addProvider(new \Sy\Bootstrap\Application\Sitemap\Page());
		$this->addProvider(new \Sy\Bootstrap\Application\Sitemap\Content()); // Add the content sitemap
	}

}

Content adds one entry to the sitemap index (<project>/sitemap/content) and lists every content whose visibility is public: <lastmod> is its updated_at date, and every language declared in LANGS gets its own URL plus an <alternate> set. With a single language in LANGS, the URL keeps lang=none.

The provider must be registered: Sitemap resolves the requested action to Project\Application\Sitemap\<Action> then Sy\Bootstrap\Application\Sitemap\<Action>, and answers 404 when no provider class matches the action or when that class was never added with addProvider(). An unregistered Content sitemap is therefore a 404, not an empty file; leaving it out of Sitemap.php also keeps the content URLs out of the sitemap index.