Welcome Guest, Not a member yet? Register   Sign In
Smarty: Assigning global variable from controller
#1

[eluser]behnampmdg3[/eluser]
Hello;
I use $this->load->vars($data); in controllers to assign global variables with Codeigniter. For example:
Code:
if($places)
    {
        foreach($places as $val)
            {
                if($val['suburb']!=$val['city'])
                    {
                        $this->suburb = ", ".$val['suburb'];
                    }
                else
                    {
                        $this->suburb="";
                    }
                $data['places'][] = array('title'=>html_escape(ucwords(strtolower($val['title']))), 'city'=>html_escape(ucwords(strtolower($val['city']))), 'date_added'=>$val['date_added'], 'suburb'=>$this->suburb, 'AID'=>$val['AID']);
            }
        $this->load->vars($data);
    }



I was wondering what is the equivalent of the code above Smarty. Cause $this->smarty->assign("places", $list_places); does not create global variables!


Code:
if($places)
    {
        foreach($places as $val)
            {
                if($val['suburb']!=$val['city'])
                    {
                        $this->suburb = ", ".$val['suburb'];
                    }
                else
                    {
                        $this->suburb="";
                    }
                $list_places[] = array('title'=>html_escape(ucwords(strtolower($val['title']))), 'city_suburb'=>html_escape(ucwords(strtolower($val['city'].$this->suburb))), 'date_added'=>$val['date_added'], 'AID'=>$val['AID']);
            }
    }
$this->smarty->assign("title", "Share accomodation in Australia");
$this->smarty->assign("places", $list_places);

Thank you
#2

[eluser]Aken[/eluser]
Smarty::assign() is the standard way to assign "global" variables for Smarty. http://www.smarty.net/docs/en/language.v...scopes.tpl

If you want to see a way of integrating Smarty but keeping CI-style code (aka $this->load->view()), see my Github Repo: https://github.com/cryode/CodeIgniter_Smarty




Theme © iAndrew 2016 - Forum software by © MyBB