Giter Site home page Giter Site logo

cedcannes / knpdoctrinemediahandlerplugin Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 101 KB

A doctrine behavior that handle your model medias -- Time goes by. This project is deprecated. Feel free to contact us if you want to give rebirth to the project and being official maintainer.

PHP 100.00%

knpdoctrinemediahandlerplugin's Introduction

knpDoctrineMediaHandlerPlugin

The knpDoctrineMediaHandlerPlugin is a symfony plugin that provides a doctrine behavior making it easier to manage images attached to a model.

What it does

The behavior add some util methods to your model objects. It is also able to automatically remove medias from your filesystem when the object is updated or deleted.

Install the plugin

To begin, copy the plugin into your plugin folder.

If you want to use git:

# in your project root directory
$ git clone git://github.com/knplabs/knpDoctrineMediaHandlerPlugin.git plugins/knpDoctrineMediaHandlerPlugin

Or as a submodule:

$ git submodule add git://github.com/knplabs/knpDoctrineMediaHandlerPlugin.git plugins/knpDoctrineMediaHandlerPlugin

You must then enable the plugin in your project configuration:

// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {

    // ...

    $this->enablePlugin('knpDoctrineMediaHandlerPlugin');
  }
}

Use the behavior

The plugin provide a doctrine template and listener. To use it, you simply need to configure it in the actAs section of your model definition.*

Take the exemple of an article:

# config/doctrine/schema.yml
Article:
  actAs:
    MediaHandler:
      medias:   [illustration]
  columns:
    title:
      type:     string(127)
      notnull:  true
    illustration:
      type:     string(45)
    body:
      type:     clob

After rebuilding your doctrine model classes:

$ ./symfony doctrine:build --model

New methods are available for your Article objects:

  • getMediaPath($field [$filename = null]) gets the path of the media corresponding to the specified field. You can pass an optional filenale: it will calculate the path from the media field folder.
  • getMediaDirectory($field) gets the path of the media directory corresponding to the specified field.

The $field parameter is the name of the field configured as media (i.e. "illustration" in the article).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.