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

Thanks you all for you help, i solved the problem,  I tried you guys solution but it isn't worked!
i shared my solution here in case that someone may face the same problem

First in the controller i replace the extend
From:

Code:
class Rss extends BaseController

To:
PHP Code:
use CodeIgniter\Controller;

class 
Rss extends Controller 

Second i remove the header function in the view file
Finally fix the index function in the controller use CI response->setheader + setBody for this
PHP Code:
    public function index()
    {
        $postData model(PostModel::class)
            ->join('post_content''post_content.post_id = post.id''LEFT')
            ->where('lang_id'$this->lang->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);
        }

        $this->response->setHeader('Content-Type''application/xml;charset=UTF-8');
        $html view('rss'$this->feeds->getData(), ['debug' => false]);
        return $this->response->setBody($html);
    
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB