2017 © Pedro Peláez
 

symfony-bundle news-bundle

Simple news bundle with sonata backend

image

sip/news-bundle

Simple news bundle with sonata backend

  • Saturday, May 18, 2013
  • by iljasuhinin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Simple news bundle with sonata backend

The bundle implements the news on the site, there is also the opportunity to share the news site and news on the home page (using the checkboxes in the admin on mayn), allow orm and mongodb, (*1)

Installation

1. command to add the bundle to your composer.json and download package.

``` bash $ composer require "sip/news-bundle": "dev-master", (*2)


2. Enable the bundle inside the kernel. --------------------------------------- ``` php <?php // app/AppKernel.php public function registerBundles() { $bundles = array( new SIP\NewsBundle\SIPNewsBundle(), new Genemu\Bundle\FormBundle\GenemuFormBundle(), // If you wish to use SonataAdmin new Sonata\BlockBundle\SonataBlockBundle(), new Sonata\jQueryBundle\SonatajQueryBundle(), new Sonata\AdminBundle\SonataAdminBundle(), // Other bundles... ); }

Read more about installation SonataAdminBundle, (*3)

3. Creating your entity/document

for orm: ``` php <?php namespace MyBundle\Entity;, (*4)

use Doctrine\ORM\Mapping as ORM; use SIP\NewsBundle\Entity\News as BaseNews;, (*5)

/** * @ORM\Entity * @ORM\Table(name="content_news") */ class News extends BaseNews { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id;, (*6)

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

}, (*7)


for mongodb: ``` php <?php namespace MyBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; use SIP\NewsBundle\Document\News as BaseNews; /** * @MongoDB\Document(collection="content_news") */ class News extends BaseNews { /** * @MongoDB\Id */ protected $id; /** * Get id * * @return integer */ public function getId() { return $this->id; } }

4. Updating database schema(only for orm)

``` bash $ php app/console doctrine:schema:update --force, (*8)


This should be done only in dev environment! We recommend using Doctrine migrations(only for orm), to safely update your schema. 5. Importing routing configuration ---------------------------------- ``` yml SIPNewsBundle: resource: '@SIPNewsBundle/Resources/config/routing.yml' prefix: /news

6. Configuration:

for orm:, (*9)

``` yml, (*10)

app/config/config.yml

sip_news: model: MyBundle\Entity\News # All Default configuration: # controller: SIP\NewsBundle\Controller\NewsController # manager_type: orm # repository: Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository # admin: SIP\NewsBundle\Admin\NewsAdmin, (*11)


for mongodb: ``` yml # app/config/config.yml sip_news: model: MyBundle\Document\SIP\News # controller: SIP\\NewsBundle\\Controller\\NewsController manager_type: mongodb repository: SIP\ResourceBundle\Repository\ODM\MongoDB\DocumentRepository # admin: SIP\NewsBundle\Admin\NewsAdmin

7. Templates

The bundle requires show.html and list.html templates. Easiest way to override the view is placing it here app/Resources/SIPNewsBundle/views/News/index.html.twig app/Resources/SIPNewsBundle/views/News/item.html.twig app/Resources/SIPNewsBundle/views/News/main_index.html.twig., (*12)

8. Usage

Show news on main page:, (*13)

Controller:, (*14)

``` php <?php, (*15)

namespace MyBundle\Controller;, (*16)

use Symfony\Bundle\FrameworkBundle\Controller\Controller;, (*17)

class MainController extends Controller { /** * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction() { $recentNews = $this ->getNewsRepository() ->findBy(array('onMain' => 1), array('date' => 'desc'), 8);, (*18)

    return $this->render('MyBundle:Main:index.html.twig',
        array('recentNews'     => $recentNews));
}

}, (*19)


Template(index.html.twig): ``` twig ...
{% for news in recentNews %}
{% media news.image, 'normal' %}

{{ news.title|slice(0, 20) }}...

{{ news.description|slice(0, 50)|raw }}..., (*20)

Read more , (*21)

{% if loop.index % 4 == 0 %}
{% endif %} {% endfor %}
...

The Versions

18/05 2013
12/05 2013

0.1.1.x-dev

0.1.1.9999999-dev https://github.com/SIProject/SIPNewsBundle

Simple news bundle with sonata backend

  Sources   Download

MIT

The Requires

 

orm mongodb news sonataadmin

17/04 2013

0.1.0.x-dev

0.1.0.9999999-dev

Simple news bundle with sonata backend

  Sources   Download

The Requires