0

我试图让我的脚本生成 iCalendar,但 mac 日历程序一直告诉我数据无效。我正在使用 cakephp。这就是我所拥有的 - 任何线索?:

function webcal() {
    Configure::write('debug', 0); 
    $this->autoRender = false; 
    echo header( 'Content-Type: text/calendar; charset=utf-8' );  
    ?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:20110514T170000Z
DTEND:20110515T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR
    <?php
    exit(200);      
}
4

1 回答 1

0

这是在您的控制器中吗?为什么不把它放在一个单独的“空白”布局中,而不是试图破解控制器来做一些它不应该做的事情。

// controller code
function webcal(){
    Configure::write('debug', 0); 
    echo header( 'Content-Type: text/calendar; charset=utf-8' );  
    $this->layout = 'blank' // depending on what version of cakephp you're using this might be different
}

// layout code in /app/views/layout/blank.ctp
echo $content_for_layout;

// view code in /app/views/<controller>/webcal.ctp
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:20110514T170000Z
DTEND:20110515T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR

不要忘记向视图传递您可能需要的任何变量$this->set()

于 2011-05-19T18:48:36.180 回答