My app uses ical-like events and I'd like to make these events
available for subscription from Google Calendar, Apple iCal, etc. The
guide at http://www.365webapplications.com/2009/01/09/cakephp-calendar/
helped me set up iCalcreator as a Helper.

However I'm confused on use of a view template vs. element: from the
Cake doc, I would have expected to use a template that defines the
overall layout (in this case, it would be empty as iCalcreator's
render takes care of everything); then the view would create an
iCalcreator object from the data provided by the controller and render
it to $content_for_layout.

However, the 365webapplications approach invokes the controller action
via a requestAction in an element, the element then creates the
iCalcreator object renders it. No template is used. When I do this, I
find that the controller action gets called twice, and seems to get
cut off prematurely:

i.e. my controller and element (simplified):

controllers/events_controller.php:
<?
class EventsController extends AppController {

    function ical() {

        $this->helpers[] = 'ICal';  // pull in the i_cal helper
        $this->Event->recursive = 0;    // don't need associated data

        $events = $this->Event->find('all');

        // called via a requestAction?
        if (isset($this->params['requested']))  {
            echo "controllers/events_controller: requested<p>";
            return $events;
        }

        echo "controllers/events_controller, setting events<p>";
        $this->set('events', $events);
        echo "controllers/events_controller, done<p>";
    }
}
?>

views/elements/events.ctp
<?php
    echo "views/elements/events.ctp 1<p>";
    $events = $this->requestAction('events/ical');
    echo "views/elements/events.ctp 2<p>";

    $iCal->create();

    echo "views/elements/events.ctp 3<p>";
    foreach($events as $e)
    {
        $iCal->addEvent(
            $e['Event']['datestart'],
            $e['Event']['dateend'],
            $e['Event']['summary'],
            $e['Event']['description']
        );
    }
    $iCal->render();
    echo "<p>views/elements/events.ctp 4<p>";
?>

views/events/ical.ctp:
<?php
echo "views/events/ical.ctp start<p>";
//echo $this->element('events', array('cache'=>'+1 hour'));
echo $this->element('events');
echo "views/events/ical.ctp end<p>";
?>


Now, when I call the action, I get:

controllers/events_controller, setting events

controllers/events_controller, done

views/events/ical.ctp start

views/elements/events.ctp 1

controllers/events_controller: requested

views/elements/events.ctp 2

views/elements/events.ctp 3

<then some warnings about "cannot modify header" - which is fine as
I'm just debugging now, and the output of iCal->render>
BEGIN:VCALENDAR METHOD:PUBLISH ... :VEVENT END:VCALENDAR


<and that's it: the line in the element after the render doesn't get
called, nor does the line after the 'echo $this->element('events');'
in the view>

Is the above the best way to output non-HTML?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to