tgc/edit-content

此包最新版本(dev-master)没有可用的许可证信息。

...

dev-master 2017-09-19 12:47 UTC

This package is not auto-updated.

Last update: 2024-09-24 20:38:28 UTC


README

包导入

//composer.json du nouveau Projet
"require": {
  "...,"
  "tgc/edit-content": "dev-master",
  "..."
},

"repositories": [
  "...",
	{
		"type": "vcs",
		"url": "git@os1119.octey.me:Alexis/EditBundle.git"
	},
  "..."
],

"config": {
  "...",
	"secure-http": false,
  "..."
},
composer update

添加包的路由

//app/config/routing.yml
edit-content:
    resource: '@TgcEditContentBundle/Controller'
    type: annotation

管理本地语言

//app/config/services.yml
services:
  Tgc\EditContentBundle\EventSubscriber\LocaleSubscriber:
      arguments: ['%kernel.default_locale%']

激活包

<?php
// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Tgc\EditContentBundle\TgcEditContentBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
        );

        if (//...) {
            //....
            if (//...) {
                //...
                $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
            }
        }
    }
}

将可翻译扩展添加到您的映射

// app/config/config.yml
doctrine:
    orm:
        mappings:
            translatable:
                type: annotation
                is_bundle: false
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                alias: GedmoTranslatable

启用可翻译扩展

// app/config/config.yml
stof_doctrine_extensions:
    default_locale: fr
    persist_default_translation: true
    orm:
        default:
            translatable: true

安装固定数据

创建固定数据

<?php
//src/AppBundle/DataFixtures/ORM/

namespace AppBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Tgc\EditContentBundle\Entity\TextEditable;

class TextData implements FixtureInterface {

    public function load(ObjectManager $manager) {
        $contents = [
            [
              'slug' => 'presentationTitre',
              'text-fr' => 'Présentation fr',
              'text-en' => 'Presentation en'
            ]
          ];

        foreach ($contents as $content) {
            $repo = $manager->getRepository('Gedmo\\Translatable\\Entity\\Translation');
            $textEditable = new TextEditable();

            $textEditable->setSlug($content['slug']);

            $repo
                    ->translate($textEditable,'text', 'en', $content['text-en'])
                    ->translate($textEditable, 'text', 'fr', $content['text-fr'])
            ;

            $manager->persist($textEditable);
        }


        $manager->flush();
    }

}

更新数据库

php bin/console doctrine:schema:update

在$contents中添加固定数据中的数据

<?php
class TextData implements FixtureInterface {
    public function load(ObjectManager $manager) {
        $contents = [
            [
              'slug' => 'presentationChambres',
              'text-fr' => 'chambres fr',
              'text-en' => 'rooms en'
            ]
          ];

加载固定数据

php bin/console doctrine:fixtures:load

在您的控制器方法中添加代码

<?php
//src/AppBundle/Controller/DefaultController
/**
 * @Route("/{edit}", name="homepage", requirements={"edit": "|edit|preview"})
 */
public function indexAction($edit = "", Request $request)
{
		$editContentService = $this->get('edit_content');

		$result = $editContentService->getEditContent(['presentationTitre'], 'homepage', $edit, $request->getLocale());

		return $this->render('default/index.html.twig', $result);
}

在您的控制器方法中的getEditContent()函数中添加slug

<?php
 $editContentService->getEditContent(['presentationTitre','SlugToInsert'], 'homepage', '', $request->getLocale());
}

在您的视图中添加

{{ include('TgcEditContentBundle:Default:validateTextEdit.html.twig') }}
{{ include('TgcEditContentBundle:Default:textEditable.html.twig', { 'content': presentationTitre }) }}

添加缓存配置

// app/config/config.yml
doctrine_cache:
    aliases:
      tgc_cache: tgc_cache
    providers:
        tgc_cache:
        ## See https://symfony.com.cn/doc/master/bundles/DoctrineCacheBundle/reference.html
        ## For more configuration options
            type: file_system
            file_system:
                umask: 0113
                extension: 'cache'