2017 © Pedro PelΓ‘ez
 

symfony-bundle file-bundle

File bundle

image

smart-information-systems/file-bundle

File bundle

  • Thursday, February 1, 2018
  • by yk115
  • Repository
  • 1 Watchers
  • 0 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Π Π°Π±ΠΎΡ‚Π° с Ρ„Π°ΠΉΠ»Π°ΠΌΠΈ

ВрСбования:

  • php 7
  • symfony 3

Установка

  1. ΠŸΡ€ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΏΠ°ΠΊΠ΅Ρ‚ ΠΈ ссылку Π½Π° Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ Π² composer.json
{
    // ...
    "require": {
        // ...
        "SmartInformationSystems/file-bundle": "dev-master"
    },
    "repositories": [
        {
            "type" : "vcs",
            "url" : "https://github.com/SmartInformationSystems/FileBundle.git"
        }
    ]
}
  1. Π’ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ Π±Π°Π½Π΄Π» Π² app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new SmartInformationSystems\FileBundle\SmartInformationSystemsFileBundle(),
            // ...
        );
    }
}
  1. ΠŸΡ€ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ настройки Π² app/config/config.yml
smart_information_systems_file:
    storage:
        type: filesystem
        params:
            path: '%kernel.root_dir%/../web/storage'
            url: 'http://localhost/storage'

ИспользованиС

Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ Π² ΡΡƒΡ‰Π½ΠΎΡΡ‚ΡŒ

  1. ДобавляСм ΠΏΠΎΠ»Π΅ Π² Entity
use SmartInformationSystems\FileBundle\Entity\Image;
use SmartInformationSystems\FileBundle\Annotations as Files;

class Brand
{
    /**
     * Π›ΠΎΠ³ΠΎΡ‚ΠΈΠΏ
     *
     * @var Image
     *
     * @ORM\OneToOne(targetEntity="SmartInformationSystems\FileBundle\Entity\Image", cascade="all")
     * @ORM\JoinColumn(name="logo_id", referencedColumnName="id", nullable=true)
     *
     * @Files\Image(
     *   width=370, height=210,
     *   previews={
     *     @Files\Image\Preview(name="admin", width=100, height=100),
     *   }
     * )
     */
    private $logo;
}
  1. ΠŸΡ€ΠΈΠΌΠ΅Π½ΡΠ΅ΠΌ измСнСния Π² Π‘Π”

php binv/console doctrine:schema:update, (*1)

Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΎΠΊ Π² ΡΡƒΡ‰Π½ΠΎΡΡ‚ΡŒ

  1. ДобавляСм Π½ΠΎΠ²ΡƒΡŽ ΡΡƒΡ‰Π½ΠΎΡΡ‚ΡŒ
use SmartInformationSystems\FileBundle\Entity\Image;
use SmartInformationSystems\FileBundle\Annotations as Files;

class ProductImage
{
    /**
     * Π’ΠΎΠ²Π°Ρ€
     *
     * @var Product
     *
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="images")
     * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false)
     */
    private $good;

    /**
     * Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅.
     *
     * @var Image
     *
     * @ORM\OneToOne(targetEntity="SmartInformationSystems\FileBundle\Entity\Image", cascade="all")
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id", nullable=false)
     *
     * @Files\Image(
     *   width=700, height=700,
     *   previews={
     *     @Files\Image\Preview(name="admin", width=100, height=100, crop=true),
     *     @Files\Image\Preview(name="small", width=65, height=65, crop=true),
     *     @Files\Image\Preview(name="medium", width=250, height=250, crop=true)
     *   }
     * )
     */
    private $image;
}
  1. ΠŸΡ€ΠΈΠΌΠ΅Π½ΡΠ΅ΠΌ измСнСния Π² Π‘Π”

php binv/console doctrine:schema:update, (*2)

Π’Ρ‹Π²ΠΎΠ΄ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈ Π² Sonata Admin

Бписок элСмСнтов

  1. ДобавляСм ΠΏΠΎΠ»Π΅ Π² Admin класс
class BrandAdmin extends AbstractAdmin
{
    $listMapper->add('logo', 'string', [
        'template' => 'SmartInformationSystemsFileBundle:sonata-admin:list_image.html.twig',
    ]);
}

Π€ΠΎΡ€ΠΌΠ° рСдактирования

  1. Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ шаблон Π² app/config/config.yml
twig:
    form_themes:
        - 'SmartInformationSystemsFileBundle:Form:fields.html.twig'

  1. Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΏΠΎΠ»Π΅ Π² Admin класс
use SmartInformationSystems\FileBundle\Form\Type\FileType;

class BrandAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper->add('logo', FileType::class, [
            'entity_class' => Brand::class,
            'data_class' => Image::class,
            'required' => false,
        ]);
    }
}

The Versions

01/02 2018

dev-master

9999999-dev

File bundle

  Sources   Download

MIT

The Requires

 

by Avatar yk115

file image

02/03 2016

v1.0

1.0.0.0

File bundle

  Sources   Download

MIT

The Requires

 

by Avatar yk115

file image