Welcome Guest, Not a member yet? Register   Sign In
Model s and views
#1

[eluser]The Casual Bot[/eluser]
hey everyone

I know before i post this someone is going to tell me this is a bad idea and thats why im posting it

i want to load a model in a view fie

because i want it to load the number of unread messages in the nav menu

ie

Inbox [1]

but i don't what to have to make the call in my controllers and pass the variable in ever time i change controller is there a way of make this function available globally to my sidebar view file ????
#2

[eluser]Colin Williams[/eluser]
MY_Controller. Search for it.
#3

[eluser]The Casual Bot[/eluser]
not sure what I'm looking for with MY_controller

but i have worked how to get this working what i did is

Created a library
then auto loaded it so now every time A page loads it checks the db for unread msg's and updates the session

Mymsglib
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mymsglib {

    function Mymsglib()
    {
        $CI =& get_instance();
        $CI->load->library('session');
        $session = $CI->session->userdata('userid');
        if (!empty($session)) { //check to see if user is logged in
          $CI->load->model('msg_model');
          $unread = array();
          $unread['unreadmsg']= $CI->msg_model->unread();
          $CI->session->set_userdata($unread);
        }
    }
}

?>

autoload
Code:
$autoload['libraries'] = array('database', 'session', 'mymsglib');

and my sidebar view

Code:
<?=$this->session->userdata('unreadmsg')?>

but im still intrigued by My_Controller could you expand on this a little for me plz :-)
#4

[eluser]jedd[/eluser]
[quote author="The Casual Bot" date="1256776652"]
but im still intrigued by My_Controller could you expand on this a little for me plz :-)
[/quote]

Have a read of [url="/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]this wiki page[/url] on the subject.
#5

[eluser]The Casual Bot[/eluser]
thanks will do Smile
#6

[eluser]bigtony[/eluser]
In the MVC paradigm it is acceptable to make read-only calls to a model from a view, and CI will let you do this just as easily as if you were calling if from your controller (you would just pass any select parameter values into the view).




Theme © iAndrew 2016 - Forum software by © MyBB