2

I was coding PHP using controll based on adress and GET method with index.php?site=filename. Then i was including existing filename.php in content div. That was simply but effective. Also i has got notification div where i included file with data from database

I'm trying to get similar result in CodeIgniter

html
    head
    /head
    body
        div notification bar (always on top like Material)
        div menu (slide from left also like Material)
        div content (depended on controller and loaded view)
        div footer (only /body /html)
    /body
/html

by

public function __construct()
        {
            parent::__construct();
            $this -> load -> view('notification ');
            $this -> load -> view('menu '); 
        }

I want do send data from model to notification view but i can't do this in constructor. Also i dont want to load this same view in each controller's method. How should i do this? I dont expct ready solution, but some ideas, maybe pseudocode?

Or maybe this is only one solution like this? Loading all needed views in every methods? Really?

class news extends CI_Controller
    {
        public function __construct()
        {
            parent::__construct();
            $this -> load -> view('header');
        }
        public function index()
        {
            [...]//data from model
            $this -> load -> view('notification',$Data);
            $this -> load -> view('menu',$Permission);
            $this -> load -> view('news',$Content);
        }
[...]
Bejkrools
  • 1,129
  • 2
  • 17
  • 38
  • 1
    Why not simply create a view containing views (kind of like sub-views)? It's not too hard to do, see http://stackoverflow.com/questions/9402924/how-to-load-view-into-another-view-codeigniter-2-1 – SolarBear Feb 23 '15 at 21:41
  • Ok, thanks, i'll do this way, but it doesn't solve my problem with data in notification. Some of notifications will be inactive so how set whitch of them are? Or i can set this in view code using mysql query but this is against MWC rules, isn't? How do you think? – Bejkrools Feb 23 '15 at 22:03

1 Answers1

0

I'm trying this (sorry for polish words):

controller

class uzytkownik extends CI_Controller
    {
        public function index()
        {
            $this -> load -> model('Uzytkownik_model');
            $DaneLogo['Tytul'] = 'Dzie z życia';
            $Dane = array(
            'Naglowek' => $this -> load -> view('naglowek', NULL, TRUE),
            'Logo' => $this -> load -> view('logo', $DaneLogo, TRUE),
            'Lista' =>  $this -> Uzytkownik_model -> PobierzUzytkownikow(), 
            );

            $this -> load -> view('uzytkownicy', $Dane);
        }

view

echo $Naglowek;
echo $Tytul;
echo $Logo;

foreach ($Lista->result() as $Uzytkownik)
{
    echo $Uzytkownik -> id.' ';
    echo $Uzytkownik -> imie.' ';
    echo $Uzytkownik -> nazwisko.'<br>';

}

working fine but...

    <head>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/>
</head>
<body>
<div id='logo' style='background-color: blue; wight: 100%; height: 40px;'>
    <center> <!-- i want $Tytul HERE --></center>
</div>
Dzie z zycia<!-- NOT HERE -->1 Jan Kowalski<br>2 Adam Nowak<br>3 Alicja Marczak<br></div>
</body>
Bejkrools
  • 1,129
  • 2
  • 17
  • 38