Welcome Guest, Not a member yet? Register   Sign In
Problems with Dynamic Variables in a View
#1

[eluser]Gwarrior[/eluser]
Thanks to anyone who reads this.

I created my own class file that basically grabs the URL typed in the browser and tells my script which one came into the site (I have three different domains that all route to the same place), and then I made functions that a) Create a logo for that URL, b) Echo the url itself c) Echo a link.

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

class Site {

    function generate_logo($site)
    {
        if ($site == 'atcanswers.com' || $site == 'www.atcanswers.com')
        {
            echo '<a href="http://'.$site.'"><img src="/images/atc/logo.png" class="logo" alt="Around the Clock Answering Service" border="0" /></a>';
        }
        if ($site == 'ccooanswers.com' || $site == 'www.ccooanswers.com')
        {
            echo '<a href="http://'.$site.'"><img src="/images/ccoo/logo.png" class="logo" alt="Communication Centers of Ohio Answering Service" border="0" /></a>';
        }    
        if ($site == 'chi')
        {
            echo '<a href="http://'.$site.'"><img src="/images/ccoo/logo.png" class="logo" alt="Chicagoland Call Communications" border="0" /></a>';
        }                
    }
    function generate_name($site)
    {
        if ($site == 'atcanswers.com' || $site == 'www.atcanswers.com')
        {
            echo 'Around the Clock';
        }
        if ($site == 'ccooanswers.com' || $site == 'www.ccooanswers.com')
        {
            echo 'Communication Centers of Ohio';
        }        
        if ($site == 'ccoo')
        {
            echo 'Chicagoland Communications" />';
        }        
    }
    function generate_url($site)
    {
        if ($site == 'atcanswers.com' || $site == 'www.atcanswers.com')
        {
            echo 'http://www.atcanswers.com';
        }
        if ($site == 'ccooanswering.com' || $site == 'www.ccooanswering.com')
        {
            echo 'http://www.ccooanswering.com';
        }        
    }
    function generate_ss($site)
    {
        if ($site == 'atcanswers.com' || $site == 'www.atcanswers.com')
        {
            echo 'Around the Clock';
        }
        if ($site == 'ccooanswering.com' || $site == 'www.ccooanswering.com')
        {
            echo 'Communication Centers of Ohio';
        }        
        if ($site == 'ccoo')
        {
            echo '&lt;link type="stylesheet" href="" /&gt;';
        }                
    }
}

?&gt;

All is fine and good and I load them in the controller, then pass them to the view as a variable.

Code:
&lt;?php
class Home extends Controller {
    function Home()
    {
        parent::Controller();
        $this->load->library('site');
    }

    function index()
    {
        $site = $_SERVER['SERVER_NAME'];
        $data['name'] = $this->site->generate_name($site);
        $data['url'] = $this->site->generate_url($site);
        $data['ss'] = $this->site->generate_ss($site);
        $data['logo'] = $this->site->generate_logo($site);
        $this->load->view('header', $data);
        $this->load->view('home/index');
        $this->load->view('footer');
    }
}
?&gt;

And we're still working fine, but then I go to use the variable in the view and it all goes to hell. No matter where I try to echo the variable, it put it right on the top, even before the DOCTYPE declaration.

Code:
Around the Clockhttp://www.atcanswers.comAround the Clock<a href="http://atcanswers.com"><img src="/images/atc/logo.png" class="logo" alt="Around the Clock Answering Service" border="0" /></a><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;

Any ideas?

Thanks guys.


Messages In This Thread
Problems with Dynamic Variables in a View - by El Forum - 04-11-2009, 04:15 PM
Problems with Dynamic Variables in a View - by El Forum - 04-11-2009, 04:32 PM
Problems with Dynamic Variables in a View - by El Forum - 04-11-2009, 04:49 PM
Problems with Dynamic Variables in a View - by El Forum - 04-11-2009, 04:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB