ivanamat / cakephp3-documents
CakePHP 3.x - Markdown 文档
Requires
- php: >=5.4.16
- cakephp/cakephp: ~3.0
- ivanamat/cakephp3-markdown: ~1.0
This package is auto-updated.
Last update: 2024-09-04 15:29:59 UTC
README
安装
Composer {#composer}
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式是
composer require ivanamat/cakephp3-documents
Git 子模块 {#gitsubmodule}
git submodule add git@github.com:ivanamat/cakephp3-documents.git plugins/Documents
git submodule init
git submodule update
手动安装
下载 .zip 或 .tar.gz 文件,解压并将插件文件夹 "cakephp3-documents" 重命名为 "Documents",然后将其复制到您的插件文件夹。
配置
加载插件
Plugin::load('Documents', ['bootstrap' => false, 'routes' => true]);
数据库
导入 config/cheme/documents.sql 中的 documents.sql 或执行 SQL 命令。
# documents.sql DROP TABLE IF EXISTS `categories`; CREATE TABLE `categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `parent_id` int(11) DEFAULT NULL, `lft` int(11) DEFAULT NULL, `rght` int(11) DEFAULT NULL, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `public` tinyint(1) NOT NULL DEFAULT '0', `created` datetime NOT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `slug` (`slug`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `documents`; CREATE TABLE `documents` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category_id` int(11) DEFAULT NULL, `user_id` int(11) NOT NULL, `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `body` text COLLATE utf8_unicode_ci, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
引导
在您的 bootstrap 文件 src/config/bootstrap.php
中设置。
指定您主页的 URL。
Configure::write('Documents.home', ['plugin' => false, 'controller' => 'Pages', 'action' => 'display', 'home']);
创建自己的 INDEX.md 并指定路径。
Configure::write('Documents.index', '../INDEX.md');
如果加载了 ACL 插件,您可以设置操作的权限。
/** * Allow CategoriesController actions * @actions: index, edit */ Configure::write('Categories.auth.allow', ['index','edit']); /** * Allow DocumentsController actions * @actions: index, view, add, edit, delete **/ Configure::write('Documents.auth.allow', ['index','view']);
组件和助手
Documents 有一个名为 DocsComponent 的组件和一个名为 DocsHelper 的助手,它们都具有相同的方法。
方法
slugCategory($id)
$id int 类别 id
返回 string 返回类别 slug
$slug = $this->Docs->slugCategory($id); # Example $slug value: 'proyectos/cakephp/plugins' echo '<a href="/' . $this->plugin . DS . $slug . '"><strong>'.$category->title.'</strong></a>';
slugDocument($id)
$id int
返回 string 返回文档 slug
$slug = $this->Docs->slugDocument($id); # Example $slug value: 'proyectos/cakephp/plugins/cakephp-3-x-markdown-documents' echo '<a href="/' . $this->plugin . DS . $slug . '"><strong>'.$document->title.'</strong></a>';
getCategory($id)
$id int 类别 id
返回 object Category
$category = $this->Docs->getCategory($id); echo '<h2>'.$category->title.'</h2>';
getParentSlug($slug)
$slug string Slug
返回 string 父 slug
# $slug = 'projects/cakephp/plugins/cakephp-3-x-markdown-documents' $parentSlug = $this->Docs->getParentSlug($slug); # $parentSlug will output 'projects/cakephp/plugins' echo '<a href="/' . $this->plugin . DS . $parentSlug . '"><strong>Parent category</strong></a>';
getRelatedDocuments($id)
$id int 类别 id
返回 array 指定类别的子类别中的文档数组
$relatedDocuments = $this->Docs->getParentSlug($slug); foreach($relatedDocuments as $document) { echo '<h4>' . $document->title . '</h4>'; echo $this->Markdown->parse($document->body); }
CakePHP 3.x - Markdown 文档简介
CakePHP 3.x - Markdown 文档需要 CakePHP 3.x - Markdown 插件。
友好的 URL!
生成的 URL 都是 友好的。
示例: http://www.example.com/Documents/tutorials/cakephp/plugins/cakephp-3-x-documents
作者
Iván Amat on GitHub
www.ivanamat.es