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。 - 执行数据库迁移和清理缓存操作。
AutoGLM-Phone-9BAutoGLM-Phone-9B是基于AutoGLM构建的移动智能助手框架,依托多模态感知理解手机屏幕并执行自动化操作。Jinja00
Kimi-K2-ThinkingKimi K2 Thinking 是最新、性能最强的开源思维模型。从 Kimi K2 开始,我们将其打造为能够逐步推理并动态调用工具的思维智能体。通过显著提升多步推理深度,并在 200–300 次连续调用中保持稳定的工具使用能力,它在 Humanity's Last Exam (HLE)、BrowseComp 等基准测试中树立了新的技术标杆。同时,K2 Thinking 是原生 INT4 量化模型,具备 256k 上下文窗口,实现了推理延迟和 GPU 内存占用的无损降低。Python00
GLM-4.6V-FP8GLM-4.6V-FP8是GLM-V系列开源模型,支持128K上下文窗口,融合原生多模态函数调用能力,实现从视觉感知到执行的闭环。具备文档理解、图文生成、前端重构等功能,适用于云集群与本地部署,在同类参数规模中视觉理解性能领先。Jinja00
HunyuanOCRHunyuanOCR 是基于混元原生多模态架构打造的领先端到端 OCR 专家级视觉语言模型。它采用仅 10 亿参数的轻量化设计,在业界多项基准测试中取得了当前最佳性能。该模型不仅精通复杂多语言文档解析,还在文本检测与识别、开放域信息抽取、视频字幕提取及图片翻译等实际应用场景中表现卓越。00
GLM-ASR-Nano-2512GLM-ASR-Nano-2512 是一款稳健的开源语音识别模型,参数规模为 15 亿。该模型专为应对真实场景的复杂性而设计,在保持紧凑体量的同时,多项基准测试表现优于 OpenAI Whisper V3。Python00
GLM-TTSGLM-TTS 是一款基于大语言模型的高质量文本转语音(TTS)合成系统,支持零样本语音克隆和流式推理。该系统采用两阶段架构,结合了用于语音 token 生成的大语言模型(LLM)和用于波形合成的流匹配(Flow Matching)模型。 通过引入多奖励强化学习框架,GLM-TTS 显著提升了合成语音的表现力,相比传统 TTS 系统实现了更自然的情感控制。Python00
Spark-Formalizer-X1-7BSpark-Formalizer 是由科大讯飞团队开发的专用大型语言模型,专注于数学自动形式化任务。该模型擅长将自然语言数学问题转化为精确的 Lean4 形式化语句,在形式化语句生成方面达到了业界领先水平。Python00