PHP code example of dyvelop / icalcreator-bundle

1. Go to this page and download the library: Download dyvelop/icalcreator-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dyvelop / icalcreator-bundle example snippets


// File: app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new \Dyvelop\ICalCreatorBundle\DyvelopICalCreatorBundle(),
        );
        
        // ...
        
        return $bundles;
    }
    
    // ...
}

$config = array(
    'unique_id' => 'My unique calendar name',
    'format'    => 'ical',            // or 'xcal'
    'filename'  => 'my-calendar.ics'  // or 'my-calendar.xml'
);
$calendar = $this->get('dyvelop_icalcreator.factory')->create($config);

$event = $calendar->newEvent();
$event->setUid('foo');
$event->setSummary('Bar');
$event->setDtstart(2016, 10, 6, 20);
$event->setDtend(2016, 10, 6, 21);

namespace AppBundle/Controller;

use Dyvelop\ICalCreatorBundle\Response\CalendarResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        $calendar = $this->get('dyvelop_icalcreator.factory')->create();
        
        // add events to calendar etc.
        // ...
        
        return new CalendarResponse($calendar);
    }
}

use  Dyvelop\ICalCreatorBundle\Mailer\CalendarAttachment;

// create a new mail message via Swiftmailer
$mailer = $this->get('mailer');
$message = $mailer->createMessage();

// create calendar
$calendar = $this->get('dyvelop_icalcreator.factory')->create();

// add events to calendar etc.
// ...

// add calender attachment
$attachment = new CalendarAttachment($calendar);
$message->attach($attachment);

// add other message configurations like subject or body
// ...

$mailer->send($message);
yml
dyvelop_icalcreator:
    default_timezone: Europe/Berlin