eee
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<nav style="background: #f0f0f0; padding: 10px;">
|
||||
<ul style="list-style: none; display: flex; gap: 20px; margin: 0; padding: 0;">
|
||||
<li><a href="/">首页</a></li>
|
||||
<li><a href="/about">关于</a></li>
|
||||
<li><a href="/contact">联系</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>@yield('title', 'Kiri Blade 示例')</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
header {
|
||||
background: #333;
|
||||
color: white;
|
||||
padding: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
footer {
|
||||
background: #f5f5f5;
|
||||
padding: 1rem;
|
||||
margin-top: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>@yield('header', 'Kiri Blade 模板引擎')</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
@yield('content')
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© {{ date('Y') }} Kiri Framework. 使用 Blade 模板引擎构建。</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Blade 模板引擎测试示例
|
||||
*
|
||||
* 使用方法:
|
||||
* php examples/test-blade.php
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Kiri\Router\Blade\BladeFactory;
|
||||
use Kiri\Router\Blade\BladeHelper;
|
||||
|
||||
// 设置视图路径和缓存路径
|
||||
$viewPath = __DIR__ . '/';
|
||||
$cachePath = __DIR__ . '/cache';
|
||||
|
||||
// 创建 BladeFactory 实例
|
||||
$factory = new BladeFactory($viewPath, $cachePath);
|
||||
BladeHelper::setFactory($factory);
|
||||
|
||||
// 准备测试数据
|
||||
$data = [
|
||||
'name' => '张三',
|
||||
'email' => 'zhangsan@example.com',
|
||||
'age' => 28,
|
||||
'skills' => ['PHP', 'JavaScript', 'MySQL', 'Redis'],
|
||||
'posts' => [
|
||||
[
|
||||
'title' => 'Blade 模板引擎介绍',
|
||||
'content' => '这是一个类似 Laravel Blade 的模板引擎实现。',
|
||||
'date' => '2024-01-15'
|
||||
],
|
||||
[
|
||||
'title' => '如何使用 Blade',
|
||||
'content' => 'Blade 提供了简洁优雅的模板语法。',
|
||||
'date' => '2024-01-20'
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 渲染视图
|
||||
try {
|
||||
echo "开始渲染视图...\n\n";
|
||||
$html = $factory->render('user.profile', $data);
|
||||
echo $html;
|
||||
echo "\n\n渲染完成!\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "错误: " . $e->getMessage() . "\n";
|
||||
echo "文件: " . $e->getFile() . "\n";
|
||||
echo "行号: " . $e->getLine() . "\n";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title')
|
||||
用户资料 - Kiri Blade
|
||||
@endsection
|
||||
|
||||
@section('header')
|
||||
用户资料页面
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<h2>用户信息</h2>
|
||||
|
||||
@if(isset($name))
|
||||
<p><strong>姓名:</strong>{{ $name }}</p>
|
||||
@else
|
||||
<p>姓名未设置</p>
|
||||
@endif
|
||||
|
||||
@if(isset($email))
|
||||
<p><strong>邮箱:</strong>{{ $email }}</p>
|
||||
@endif
|
||||
|
||||
@if(isset($age))
|
||||
<p><strong>年龄:</strong>{{ $age }} 岁</p>
|
||||
@endif
|
||||
|
||||
<h3>技能列表</h3>
|
||||
@if(isset($skills) && is_array($skills))
|
||||
<ul>
|
||||
@foreach($skills as $skill)
|
||||
<li>{{ $skill }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@else
|
||||
<p>暂无技能</p>
|
||||
@endif
|
||||
|
||||
<h3>文章列表</h3>
|
||||
@if(isset($posts) && is_array($posts))
|
||||
<div>
|
||||
@foreach($posts as $post)
|
||||
<div style="border: 1px solid #ddd; padding: 10px; margin: 10px 0;">
|
||||
<h4>{{ $post['title'] ?? '无标题' }}</h4>
|
||||
<p>{{ $post['content'] ?? '无内容' }}</p>
|
||||
<small>发布时间:{{ $post['date'] ?? '未知' }}</small>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@else
|
||||
<p>暂无文章</p>
|
||||
@endif
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user