Welcome Guest, Not a member yet? Register   Sign In
only one view is viewed..

Hi guys, im very new to codeigniter so sorry.. Smile

namespace App\Controllers;

use CodeIgniter\Controller;

class Articles extends Controller
    public function index()

        return view('templates/header');
        return view('pages/articles_page');
        return view('templates/footer');


Im doing the most simple thing - trying to make my static page. Problem is that when i go to /articles/ it only shows the first of the views - in this example header template. In case of deleting first view i get the second one, and /articles/ pages will show 'articles_page' view. What's wrong ?? i have basically no clue.


echo  view('templates/header');
echo view('pages/articles_page');
echo view('templates/footer');

(This post was last modified: 12-20-2021, 11:30 AM by captain-sensible. Edit Reason: extra )

the basic approach to getting a view rendered with data from a controller is :

$data = [
                'title'  => 'home page ',
       echo view('home',$data);

here i get a date via my own approach and want to pass to view , i get a title so i can pass that to header.

the view is called home.php , but i only need to mention "home" for system to find it , as long as its in app/views

The best approach i've found so far is to have a html content page with suffix .php that is a whole html page , into which other content is injected; i think similar to Blade.

So I have a template called layout.php at the place I want i have :

<?= $this->renderSection('content') ?>

then i have in various static view this content :

//file called about_us.php
<?= $this->extend('layout') ?>
<?= $this->section('content') ?>

<h2> blah blah blah </h2>

<?= $this->endSection() ?>

the only difference between my static pages is the content of blah blah

So you need to look into documentation and find layouts
CMS CI4     I use Arch Linux by the way 


use echo instead of return, because function ends after the first return

reference https://www.codeigniter.com/user_guide/o...views.html

PHP Code:
namespace App\Controllers;


Articles extends Controller
    public function index()
        echo view('templates/header');
        echo view('pages/articles_page');
        echo view('templates/footer');


Theme © iAndrew 2016 - Forum software by © MyBB