PHPackages                             sy/bootstrap-article - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sy/bootstrap-article

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sy/bootstrap-article
====================

Plugin for adding Article feature

1.6.0(1y ago)06101[2 issues](https://github.com/syframework/bootstrap-article/issues)MITPHPPHP &gt;=7

Since Mar 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/syframework/bootstrap-article)[ Packagist](https://packagist.org/packages/sy/bootstrap-article)[ RSS](/packages/sy-bootstrap-article/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (26)Used By (0)

sy/bootstrap-article
====================

[](#sybootstrap-article)

[sy/bootstrap](https://github.com/syframework/bootstrap) plugin for adding "Article" feature in your [sy/project](https://github.com/syframework/project) based application.

Installation
------------

[](#installation)

From your sy/project based application directory, run this command:

```
composer install-plugin article
```

---

**NOTES**

The install-plugin command will do all these following steps:

### 1. Install package sy/bootstrap-article

[](#1-install-package-sybootstrap-article)

```
composer require sy/bootstrap-article
```

### 2. Copy database installation file into your sql directory

[](#2-copy-database-installation-file-into-your-sql-directory)

Use the database installation script: `sql/install.sql`

### 3. Copy template files

[](#3-copy-template-files)

Copy template files into your project templates directory: `protected/templates/Application/content`

### 4. Copy language files

[](#4-copy-language-files)

Copy the language folder `lang/bootstrap-article` into your project language directory: `protected/lang`

### 5. Copy SCSS files

[](#5-copy-scss-files)

Copy the scss file `scss/_bootstrap-article.scss` into your project scss directory: `protected/scss`

Import it in your `app.scss` file and rebuild the css file.

### 6. Copy assets files

[](#6-copy-assets-files)

### 7. Run composer build

[](#7-run-composer-build)

### 8. Run composer db migrate

[](#8-run-composer-db-migrate)

---

Page methods
------------

[](#page-methods)

Create 2 methods in your `Project\Application\Page` class (in `protected/src/Application/Page.php`):

```
	/**
	 * List of all articles page
	 */
	public function articlesAction() {
		$components = [
			'NAV'         => new \Sy\Bootstrap\Component\Article\Nav('articles'),
			'SEARCH_FORM' => new \Sy\Bootstrap\Component\Article\Search(),
			'FEED'        => new \Sy\Bootstrap\Component\Article\Feed(),
		];

		// Add article modal button
		$service = \Project\Service\Container::getInstance();
		if ($service->user->getCurrentUser()->hasPermission('article-create')) {
			$components['ADD_FORM'] = new \Sy\Bootstrap\Component\Article\Add(['class' => 'mb-3']);
		}

		$this->setContentVars($components);
	}

	/**
	 * Article page
	 */
	public function articleAction() {
		// Redirection if no article id provided
		$id = $this->get('id');
		if (is_null($id)) throw new \Sy\Bootstrap\Application\Page\NotFoundException();

		// Detect language
		$service = \Project\Service\Container::getInstance();
		$lang = $service->lang->getLang();

		// Retrieve article
		$article = $service->article->retrieve(['id' => $id, 'lang' => $lang]);

		if (empty($article)) {
			$lang = LANG;
			$article = $service->article->retrieve(['id' => $id, 'lang' => $lang]);
		}
		if (empty($article)) throw new \Sy\Bootstrap\Application\Page\NotFoundException();

		// Article content
		$content = new \Sy\Bootstrap\Component\Article\Content($id, $lang);

		$this->setContentVars([
			'ARTICLE_BREADCRUMB' => new \Sy\Bootstrap\Component\Article\Breadcrumb($id, $lang),
			'ARTICLE_CONTENT'    => $content,
			'ARTICLE_AUTHOR'     => new \Sy\Bootstrap\Component\Article\Author($article['user_id']),
			'SIDE'               => new \Sy\Bootstrap\Component\Article\Side($id, $article['category_id']),
			'SHARE'              => new \Sy\Bootstrap\Component\Share\Buttons(PROJECT_URL . Url::build('page', 'article', ['id' => $id])),
		]);
	}
```

Add URL converter in Application.php
------------------------------------

[](#add-url-converter-in-applicationphp)

In `protected/src/Application.php`

```
