Welcome Guest, Not a member yet? Register   Sign In
Dynamic Header That Needs A Different HTML Structure
#3

[eluser]piehouserat[/eluser]
Ah I didn't think about that because I thought all logic like that was done in the controller? Well my controller now looks like this:

Code:
function index()
    {
        $header_data['page_title']    = 'Home';
        
        if (!$this->tank_auth->is_logged_in()) {
            $this->load->view('includes/header', $header_data);
        } else {
            $header_data['user_id']    = $this->tank_auth->get_user_id();
            $header_data['username']    = $this->tank_auth->get_username();
            $this->load->view('includes/header', $header_data);
        }
        
        $footer_data['copy_year']    = date('Y');
        $this->load->view('includes/footer', $footer_data);
    }

and I've modified my header view to contain this:

Code:
...
        <ul id="nav">
            &lt;?php
            if (!$this->tank_auth->is_logged_in()) {
            ?&gt;
            <li id="t-signin">
                &lt;?php echo anchor('/auth/login/', 'Sign in'); ?&gt;
            </li>
            &lt;?php
            } else {
            ?&gt;
            <li id="t-profile">
                <a href="/&lt;?php echo $username; ?&gt;" class="url" rel="contact">You</a>
                <ul class="tabs">
                    <li>&lt;?php echo anchor('/' . $username, 'Your profile'); ?&gt;</li>
                    <li>&lt;?php echo anchor('/account', 'Your account'); ?&gt;</li>
                    <li>&lt;?php echo anchor('/auth/logout/', 'Sign out'); ?&gt;</li>
                </ul>
            </li>
            &lt;?php
            }
            ?&gt;
...

And this all works well Smile
But is this good MVC architecture? I thought all application logic was meant to be kept out of the view and in the controller?

Thanks again


Messages In This Thread
Dynamic Header That Needs A Different HTML Structure - by El Forum - 02-17-2011, 08:37 AM
Dynamic Header That Needs A Different HTML Structure - by El Forum - 02-17-2011, 10:16 AM
Dynamic Header That Needs A Different HTML Structure - by El Forum - 02-17-2011, 11:02 AM
Dynamic Header That Needs A Different HTML Structure - by El Forum - 02-17-2011, 11:10 AM
Dynamic Header That Needs A Different HTML Structure - by El Forum - 02-18-2011, 02:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB