【问题标题】:Adding page in SimpleCMSBundle programmatically以编程方式在 SimpleCMSBundle 中添加页面
【发布时间】:2013-12-26 08:02:51
【问题描述】:

我正在寻找一种在 SimpleCMSBundle 中以编程方式添加页面的方法。我找到了以下命令行。

php app/console doctrine:phpcr:migrator page --identifier=/cms/simple/test

我需要的首先是上述命令的程序等效项,其次是上述命令假定存在位于 'app/Resources/data/ 的 .yml 文件 pages/test.yml,我也想以编程方式提供此信息。

我正在使用 Symfony CMF 标准版。

【问题讨论】:

    标签: symfony symfony-cmf


    【解决方案1】:

    SimpleCmsBundle 提供了两种创建页面的方式:

    1。创建一个将被解析的 yaml 文件

    这是由 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,并创建新页面!

    2。持久化文档

    对 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

    【讨论】:

      猜你喜欢
      • 2010-09-16
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多