unisharp / laravel-pagerender
提供渲染具有父子关系的常规页面的功能。
1.0.0
2015-10-13 05:02 UTC
Requires
- php: >=5.5.0
- illuminate/support: >=5.0.0
This package is auto-updated.
Last update: 2024-09-15 14:27:33 UTC
README
- 通过别名(aboutus、service等)找到您的页面,忘记ID。
- 支持父子结构的页面。
- 支持不同页面的自定义视图。
- 支持面包屑(具有祖先函数)。
安装
-
安装包
composer require unisharp/laravel-pagerender
-
在您的模型中使用特性
use \Unisharp\Pagerender\PageRenderTrait; private $default_view = 'page.show';
-
确保您的表有这些列:
parent_id
、alias
、custom_view
public function up() { Schema::create('models', function(Blueprint $table) { // ... $table->string('alias'); $table->integer('parent_id')->unsigned()->nullable(); $table->string('custom_view', 128)->nullable(); // ..
用法
$page = new Page(); $page->render(); // Generates the default view(or custom view if the column is not empty). $page->summary('content', 7); // Shorten words of a column, ex: The PHP... $page->getByAlias('aboutus'); // Get the about us page. $page->hasByAlias('aboutus'); // Check if the about us page exists. $page->allWithAlias(); // Get pages that have alias. $page->subs; // Get children pages. $page->hasSubs(); // Check if children pages exist. $page->parent; // Get parent page. $page->hasParent(); // Check if parent page exists. $page->roots(); // Get all pages at top level. $page->isRoot(); // Check if this page is at top level. $page->getLevel(); // Get level count(top level as 0). $page->ancestors(); // Get all parent pages of the current page.
待办事项
$page->tree(); // Get all pages with parent-child structure.