SonataNewsBundle 技术文档
1. 安装指南
SonataNewsBundle 是一个基于 Symfony 的新闻管理bundle。在安装前,请确保您的环境满足以下要求:
- PHP 版本 7.2 或更高
- Symfony 版本 3.x 或 4.x
以下是安装 SonataNewsBundle 的步骤:
-
使用 Composer 安装:
composer require sonata-project/news-bundle -
在
config/bundles.php文件中注册 Bundle:return [ // ... Sonata\NewsBundle\SonataNewsBundle::class => ['all' => true], // ... ]; -
配置数据库连接。编辑
config/packages/doctrine.yaml文件,根据您的数据库类型设置相应的参数。 -
执行数据库迁移:
php bin/console doctrine:schema:update --force -
清理缓存:
php bin/console cache:clear --env=prod --no-debug
2. 项目的使用说明
SonataNewsBundle 提供了新闻管理功能,包括新闻创建、编辑、删除和显示。以下是如何使用这个 Bundle:
-
创建新闻:
使用
Sonata\AdminBundle\Admin\Admin类来管理新闻实体。// src/Admin/PostAdmin.php namespace App\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Show\ShowMapper; class PostAdmin extends AbstractAdmin { protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('title') ->add('body') ->add('author') // ... ; } protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('title') ->add('author') ->add('created_at') // ... ; } protected function configureShowFields(ShowMapper $showMapper) { $showMapper ->add('title') ->add('body') ->add('author') ->add('created_at') // ... ; } } -
显示新闻列表:
在控制器中,注入
Sonata\AdminBundle\Admin\AdminManager服务,并使用它来获取新闻列表。// src/Controller/NewsController.php namespace App\Controller; use Sonata\AdminBundle\Admin\AdminManager; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; class NewsController extends AbstractController { private $adminManager; public function __construct(AdminManager $adminManager) { $this->adminManager = $adminManager; } public function index(): Response { $posts = $this->adminManager->getAdminByClass(PostAdmin::class) ->getDashboardHomepageBlocks(); return $this->render('news/index.html.twig', compact('posts')); } } -
创建新闻详情页:
使用 SonataNewsBundle 提供的
Post实体来显示新闻详情。{# templates/news/show.html.twig #} <h1>{{ post.title }}</h1> <p>{{ post.body }}</p> <p>作者:{{ post.author }}</p> <p>发布时间:{{ post.created_at }}</p>
3. 项目API使用文档
SonataNewsBundle 没有内置的 API 功能,但您可以使用 Symfony 的 API Platform 或其他 API 构建工具来创建一个基于 SonataNewsBundle 的 API。
以下是一个简单的例子,使用 API Platform 来创建一个新闻 API:
-
安装 API Platform:
composer require api-platform/core -
在
config/packages/api_platform.yaml中配置 API Platform:api_platform: title: Sonata News API version: v1 endpoints: /news: name: news_list methods: [GET] normalization_context: {'groups': ['news:read']} /news/{id}: name: news_read methods: [GET] normalization_context: {'groups': ['news:read']} -
创建一个实体表示新闻,并在
config/packages/api_platform.yaml中声明:api_platform: # ... models: App\Entity\News: short_name: News graphql: type: Mutation query: false input: App\Entity\News payload: App\Entity\NewsInput -
创建一个控制器来处理 API 请求:
// src/Controller/NewsController.php namespace App\Controller; use App\Entity\News; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; class NewsController extends AbstractController { public function getNews(Request $request): JsonResponse { $id = $request->get('id'); $news = $this->getDoctrine()->getRepository(News::class)->find($id); if (!$news) { return new JsonResponse(['message' => 'News not found'], 404); } return new JsonResponse($news); } public function getNewsList(Request $request): JsonResponse { $news = $this->getDoctrine()->getRepository(News::class)->findAll(); return new JsonResponse($news); } }
4. 项目安装方式
SonataNewsBundle 可以通过以下方式安装:
使用 Composer
推荐使用 Composer 来安装 SonataNewsBundle。在命令行中执行以下命令:
composer require sonata-project/news-bundle
然后按照上文提到的步骤完成安装。
手动安装
- 下载 SonataNewsBundle 的最新稳定版本。
- 将下载的文件解压到项目的
bundles目录下。 - 在
config/bundles.php文件中注册 Bundle。 - 执行数据库迁移和清理缓存操作。
ERNIE-4.5-VL-28B-A3B-ThinkingERNIE-4.5-VL-28B-A3B-Thinking 是 ERNIE-4.5-VL-28B-A3B 架构的重大升级,通过中期大规模视觉-语言推理数据训练,显著提升了模型的表征能力和模态对齐,实现了多模态推理能力的突破性飞跃Python00
unified-cache-managementUnified Cache Manager(推理记忆数据管理器),是一款以KV Cache为中心的推理加速套件,其融合了多类型缓存加速算法工具,分级管理并持久化推理过程中产生的KV Cache记忆数据,扩大推理上下文窗口,以实现高吞吐、低时延的推理体验,降低每Token推理成本。Python03
Kimi-K2-ThinkingKimi K2 Thinking 是最新、性能最强的开源思维模型。从 Kimi K2 开始,我们将其打造为能够逐步推理并动态调用工具的思维智能体。通过显著提升多步推理深度,并在 200–300 次连续调用中保持稳定的工具使用能力,它在 Humanity's Last Exam (HLE)、BrowseComp 等基准测试中树立了新的技术标杆。同时,K2 Thinking 是原生 INT4 量化模型,具备 256k 上下文窗口,实现了推理延迟和 GPU 内存占用的无损降低。Python00
Spark-Prover-X1-7BSpark-Prover 是由科大讯飞团队开发的专用大型语言模型,专为 Lean4 中的自动定理证明而设计。该模型采用创新的三阶段训练策略,显著增强了形式化推理能力,在同等规模的开源模型中实现了最先进的性能。Python00
MiniCPM-V-4_5MiniCPM-V 4.5 是 MiniCPM-V 系列中最新且功能最强的模型。该模型基于 Qwen3-8B 和 SigLIP2-400M 构建,总参数量为 80 亿。与之前的 MiniCPM-V 和 MiniCPM-o 模型相比,它在性能上有显著提升,并引入了新的实用功能Python00
Spark-Formalizer-X1-7BSpark-Formalizer 是由科大讯飞团队开发的专用大型语言模型,专注于数学自动形式化任务。该模型擅长将自然语言数学问题转化为精确的 Lean4 形式化语句,在形式化语句生成方面达到了业界领先水平。Python00
GOT-OCR-2.0-hf阶跃星辰StepFun推出的GOT-OCR-2.0-hf是一款强大的多语言OCR开源模型,支持从普通文档到复杂场景的文字识别。它能精准处理表格、图表、数学公式、几何图形甚至乐谱等特殊内容,输出结果可通过第三方工具渲染成多种格式。模型支持1024×1024高分辨率输入,具备多页批量处理、动态分块识别和交互式区域选择等创新功能,用户可通过坐标或颜色指定识别区域。基于Apache 2.0协议开源,提供Hugging Face演示和完整代码,适用于学术研究到工业应用的广泛场景,为OCR领域带来突破性解决方案。00