Welcome Guest, Not a member yet? Register   Sign In
display common data accross all pages
#1

[eluser]atno[/eluser]
Hi,

I need to display some data like username, rank, images, across all pages of the application, is there a quick way or a technique, pattern to do it instead of writing the same queries on every controller in every function?

atno
#2

[eluser]InsiteFX[/eluser]
Use a MY_Controller

InsiteFX
#3

[eluser]atno[/eluser]
[quote author="InsiteFX" date="1306791690"]Use a MY_Controller

InsiteFX[/quote]

Doesn't work
#4

[eluser]InsiteFX[/eluser]
What do you mean by it does not work?

You need to retrive everything in the MY_Controller then extend all your other controllers from the MY_Controller

Also you need to add this to application/config/config.php
Code:
/*
| -------------------------------------------------------------------
|  Native Autoload - by Phil Sturgeon. New Version!
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
| If using HMVC you do not need this! HMVC will autoload.
|
| Place this code at the bottom of your application/config/config.php file.
*/
function __autoload($class)
{
    if (strpos($class, 'CI_') !== 0)
    {
        if (file_exists($file = APPPATH . 'core/' . $class . EXT))
        {
            include $file;
        }

        elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
        {
            include $file;
        }
    }
}

InsiteFX
#5

[eluser]atno[/eluser]
[quote author="InsiteFX" date="1306794978"]

What do you mean by it does not work?

Also you need to add this to application/config/config.php

[/code]

InsiteFX[/quote]

meh
#6

[eluser]atno[/eluser]
what i'm trying to do is


MY_Controller
Code:
class MY_Controller extends CI_Controller {
    function __construct()
    {
        parent::__construct();
        $data = array();
        $data['top_right'] = $this->manage_model->top_right();
    }

a_view.php
Code:
var_dump($top_right);

but i get

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: top_right

Filename: views/arxiki.php

Line Number: 1

what am i doing wrong?
#7

[eluser]n0xie[/eluser]
You're not passing the $data array to your view.
#8

[eluser]atno[/eluser]
[quote author="n0xie" date="1306797868"]You're not passing the $data array to your view.[/quote]

i am through MY_Controller as insitefx suggested, im passing the $data in the view

Code:
$this->load->view('arxiki',$data);
#9

[eluser]InsiteFX[/eluser]
As n0xie Stated! Your not passing the data to your view.

Code:
class MY_Controller extends CI_Controller {

    public $data = array();

    function __construct()
    {
        parent::__construct();
         $this->data['top_right'] = $this->manage_model->top_right();
    }

// View:
$this->load->view('arxiki', $this->data);

or like this:
Code:
class MY_Controller extends CI_Controller {

    public $data = array();

    function __construct()
    {
        parent::__construct();
        $this->data['top_right'] = $this->manage_model->top_right();
        $this->load->vars($this->data);
    }

// View:
$this->load->view('arxiki');

InsiteFX
#10

[eluser]John_Betong_002[/eluser]
I had a similar problem and solved it like this:

Code:
// MY_Controller()

  //==================================================
  function __construct()
  {
    parent::__construct();

    // update top-10 today
    $this->today = $this->m_lib->today_hits_get_links();    
  }

// view
  // $this->load->helper('html');
  echo ul($this->today, $attributes);
 
I am curious to know the advantages of using $this->load->vars($this->data);
 
 
 




Theme © iAndrew 2016 - Forum software by © MyBB