쪼렙 as! 풀스택

2018. 12. 10. PHP - CodeIgniter 로, RSS 피드해주기. 본문

개발 일지/Web & Server

2018. 12. 10. PHP - CodeIgniter 로, RSS 피드해주기.

코코앱 2018. 12. 11. 16:04

회사에서 FANZEEL.COM 에 RSS 기능을 개발하라는 명령이 떨어졌다.


fanzeel.com 의 API 서버는 PHP - CodeIgniter 로 되어있다. fanzeel.com/rss 이런주소로 되길 원했기 때문에, Rss 컨트롤러를 하나 만들었다.



public class Rss extends CI_Controller -

header("Content-Type: application/rss+xml");
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';

$datas = 'DATA FROM DATABASE'

$now = date("D, d M Y H:i:s T"); // 시간 지정 (현재시간 단위~ )
$this->load->view('rss_v', array('now'=>$now, 'datas'=>$datas));



rss_v.php

<rss version="2.0">
<channel>
<title>채널 제목</title>
<link>https://fanzeel.com</link>
<description>채널 설명글</description>
<language>ko</language>
<pubDate><?=$now?></pubDate>
<managingEditor>이메일 주소</managingEditor>

<?php foreach ($datas as $item): ?>

<?php
    $linkUrl = 'https://LINK.URL/ITEM_URL'
?>

<item>
<title><?= htmlentities($item->title) ?></title>
<link><?= $linkUrl ?></link>
<description>
<?= htmlentities('<style type="text/css">img{max-width:100%;}</style>') ?>
<?= htmlentities('<div style="width:100%;">') ?>
<?= htmlentities($item->DESCRIPTION_DETAIL) ?>
<?= htmlentities('</div>') ?>
</description>
<category><?= htmlentities($item->CATEGORY_TITLE) ?></category>
<author><?= htmlentities($item->USER_NAME) ?></author>
<guid><?= $linkUrl ?></guid>
<link><?= $linkUrl ?></link>
<pubDate><?= $item->PUBLISH_DATE ?></pubDate>
</item>
<?php endforeach; ?>

</channel>
</rss>


Comments