punn/laymode
此包已被废弃,不再维护。未建议替代包。
适用于桌面和移动端的布局系统
dev-master
2014-05-24 22:37 UTC
Requires
- php: >=5.3.0
- illuminate/support: 4.1.*
This package is not auto-updated.
Last update: 2017-04-21 07:51:49 UTC
README
这是一个简单的布局模式管理器,允许您使用“视图集”自定义页面。此外,您可以通过数据库管理您的路由、页面和视图。
当前版本
1.0.3
阶段
Alpha
安装方法
- 添加到
composer.json
"require": {
"punn/laymode": "dev-master"
},
- 将
'Punn\Laymode\LaymodeServiceProvider'添加到app/config/app.php中的providers数组(Laravel v4.*) - 将
'Layout' => 'Punn\Laymode\Facades\Laymode'添加到app/config/app.php中的aliases数组 - 加载一个随机页面以在数据库中创建表格
- 在laravel项目目录的终端中运行
php artisan view:publish punn/laymode - 将路由添加到数据库
- 添加与路由ID匹配的页面
- 对于桌面和移动等布局表格,使用此方法开始
{"top":[{"module":"sets.header.one","class":"","options":[]}],"drawer":[],"content":[{"module":"modules.homepage","class":"","options":[]},{"module":"modules.html","class":"","options":{"payload_id":1}}],"footer":[{"module":"modules.footer.copyright","class":"","options":[]},{"module":"modules.footer.socialbuttons","class":"","options":[]},{"module":"modules.footer.links","class":"","options":[]}]}
或通过临时路由(如'/layout',您需要创建)创建自己的布局
Route::get('/layout', function() { $layout = array( "top" => array( array( "module" => "sets.header.one", "class" => "", "options" => array() ) ), "drawer" => array( ), "content" => array( array( "module" => "modules.homepage", "class" => "", "options" => array( ) ), array( "module" => "modules.html", "class" => "", "options" => array( "payload_id" => 1 ) ) ), "footer" => array( array( "module" => "modules.footer.copyright", "class" => "", "options" => array() ), array( "module" => "modules.footer.socialbuttons", "class" => "", "options" => array() ), array( "module" => "modules.footer.links", "class" => "", "options" => array() ) ), ); echo "<textarea>" . json_encode($layout) . "</textarea>"; });
- 第一级键“top”、“drawer”、“content”和“footer”称为'slots'(槽)
- 在槽内是模块或视图,通过数组附加了选项
- 创建一个名为
LayoutController.php的控制器并将其放置在那里
class LayoutController extends BaseController { public function home() { return Layout::get('home'); } public function detect($page) { return Layout::get($page); } }
- 将主页路由指向使用LayoutController和home操作,或手动LayoutController@home
- 确保您有一个名为'home'的页面指向主页路由ID(例如'/')
- 在
app文件夹内创建一个名为templates的文件夹 - 将模板
desktop.homepage添加到laymodes_templates数据库表中,不要考虑json_slots(在测试中) - 创建一个桌面布局,使用上面示例中使用的json编码的json_views... 模板 = 您刚刚创建的主页模板的ID
- 在步骤11中创建的
templates文件夹内创建一个名为desktop的文件夹 - 创建一个名为
homepage.blade.php的视图并添加以下内容
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title><?=$page->get_meta_title()?></title>
<? $description = $page->get_meta_description(); ?>
@if(!empty($description) || strlen($description) < 10)
<meta name="description" content="<?=$description?>" />
@endif
@if($page->get_noindex() == '1')<meta name="robots" content="noindex,nofollow" />@else<meta name="robots" content="index,follow,noodp" />@endif
<link rel="canonical" href="{{ url($_SERVER['REQUEST_URI']) }}" />
<meta name="viewport" content = "width=device-width"/>
<!-- DEFAULT STYLES -->
@if($page->get_layout()->get_template_raw())
<link rel="stylesheet" href="/css/output/templates/{{ $page->get_layout()->get_template_raw() }}.css" />
@endif
</head>
<body>
<div id="wrapper" class="page">
{{ Layout::getSlot('top'); }}
{{ Layout::getSlot('drawer'); }}
{{ Layout::getSlot('content'); }}
</div>
{{ Layout::getSlot('footer'); }}
</body>
</html>
- 加载主页以验证其是否正常工作
- 尝试不同的视图