Welcome Guest, Not a member yet? Register   Sign In
Remove blank line when render view in CI4
#1

(This post was last modified: 01-24-2024, 08:58 PM by tmtuan.)

Hi, i have a problem with the view render, it always render a blank line at the top of the html file, how can i remove that?

[Image: OLGXgxX.jpg]

in my source code i tried with the view renderer or the view function all of them show the same result

My code in controller

PHP Code:
$postData model(PostModel::class)
            ->join('post_content''post_content.post_id = post.id''LEFT')
            ->where('lang_id'$this->_data['curLang']->id)
            ->where('post_status''publish')
            ->where('post_type'PostTypeEnum::POST)
            ->orderBy('post.id''desc')
            ->select('post.id, post.user_init, post.post_type, post.created_at, post_content.title, post_content.slug, post_content.description')
            ->findAll(500);

        // add posts to the feed
        foreach ($postData as $post) { //dd($post->author);
            $this->feeds->add($post->title$post->url$post->created_at$post->author$post->slug$post->description$post->categories);
        }

        $renderer  single_service('renderer');

        return $renderer
            
->setData($this->feeds->getData())
            ->render('rss'); 


PHP Code:
$postData model(PostModel::class)
            ->join('post_content''post_content.post_id = post.id''LEFT')
            ->where('lang_id'$this->_data['curLang']->id)
            ->where('post_status''publish')
            ->where('post_type'PostTypeEnum::POST)
            ->orderBy('post.id''desc')
            ->select('post.id, post.user_init, post.post_type, post.created_at, post_content.title, post_content.slug, post_content.description')
            ->findAll(500);

        // add posts to the feed
        foreach ($postData as $post) { //dd($post->author);
            $this->feeds->add($post->title$post->url$post->created_at$post->author$post->slug$post->description$post->categories);
        }

        return view('rss'$this->feeds->getData(), ['debug' => false]); 


My code in view file

PHP Code:
<?php
/**
 * @author tmtuan
 * @github https://github.com/tu801
 * created Date: 1/24/2024
 */
header('Content-type: application/rss+xml; charset=utf-8');
echo 
'<?xml version="1.0" encoding="'$channel['encoding'] .'" ?>'//print_r($items); exit;
?>
<rss version="2.0">
    <channel>
        <title><?php echo $channel['title']; ?></title>
        <link><?php echo $channel['link']; ?></link>
        <description><?php echo $channel['description']; ?></description>
        <pubDate><?php echo $channel['pub_date'?></pubDate>
        <language><?php echo $channel['language']; ?></language>
        <copyright><?php echo $channel['copyright']; ?></copyright>
        <generator><?php echo $channel['generator']; ?></generator>
        <docs><?php echo $channel['docs']; ?></docs>
        <?php if ( !empty($channel['web_master_email']) ) : ?>
        <webMaster><?php echo $channel['web_master_email']; ?></webMaster>
        <?php endif; ?>
        <ttl>20</ttl>
        <?php if (!empty($items)): ?>
            <?php foreach ($items as $item): ?>
                <item>
                    <title><?php echo xml_convert($item['title']); ?></title>
                    <link><?php echo site_url($item['link']) ?></link>
                    <pubDate><?php echo date('D, d M Y H:i:s O'$item['pub_date']->getTimestamp()) ?></pubDate>
                    <author><?php echo $item['author']->username ?></author>
                    <guid isPermaLink="true"><?php echo site_url($item['slug']) ?></guid>
                    <description><![CDATA[<?php echo strip_tags(html_entity_decode($item['description'])); ?>]]></description>
                    <?php if (!empty($item['categories'])): ?>
                    <?php foreach ($item['categories'] as $category): ?>
                        <category><![CDATA[<?php echo $category['title'];?>]]></category>
                    <?php endforeach; ?>
                    <?php endif; ?>
                </item>
            <?php endforeach; ?>
        <?php endif; ?>
    </channel>
</rss> 


Can anyone help me to remove that blank line please
Reply


Messages In This Thread
Remove blank line when render view in CI4 - by tmtuan - 01-24-2024, 08:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB