我正在寻找一种在 SimpleCMSBundle 中以编程方式添加页面的方法。我找到了以下命令行。
php app/console doctrine:phpcr:migrator page --identifier=/cms/simple/test
我需要的首先是上述命令的编程等效项,其次上述命令假定存在位于 'app/Resources/data/pages/test.yml 的 .yml 文件,我也想以编程方式提供此信息。
我正在使用 Symfony CMF 标准版。
我正在寻找一种在 SimpleCMSBundle 中以编程方式添加页面的方法。我找到了以下命令行。
php app/console doctrine:phpcr:migrator page --identifier=/cms/simple/test
我需要的首先是上述命令的编程等效项,其次上述命令假定存在位于 'app/Resources/data/pages/test.yml 的 .yml 文件,我也想以编程方式提供此信息。
我正在使用 Symfony CMF 标准版。
SimpleCmsBundle 提供了 2 种创建页面的方法:
这是由 DataFixture 完成的。AcmeDemoBundle 自带了这样一个 yaml 文件,你可以用它来添加自己的页面:
# src/Acme/MainBundle/Resources/data/page.yml
static:
# ...
my_new_page:
name: "my_page"
label: "My Page"
title: "My new Page"
body: "I've added this when following instructions on SO"
现在您需要执行php app/console doctrine:phpcr:fixtures:load
,它将执行 DataFixtures,并创建新页面!
yaml 数据的真正作用Page
是在 PHPPCR 树中创建并保存一个文档。在 DataFixture 中,或在要添加页面的控制器/管理员中,执行以下操作:
use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
// ...
$page = new Page();
$page->setName('my_other_page');
$page->setLabel('My other Page');
$page->setTitle('My other Page');
$page->setBody('I\'ve added this myself!!');
$documentManager = ...; // get the document manager, the first argument of DataFixture::load or $container->get('doctrine_phpcr')->getManager()
$root = $documentManager->find(null, '/cms/simple'); // get the root document
$page->setParent($root); // add document to the root
$documentManager->persist($page); // add the page in the queue for persisting
$documentManager->flush(); // execute the queries
更多信息:http ://symfony.com/doc/current/cmf/book/database_layer.html