can not pass varibles to view |
the following s my controller code.I new to codeigniter..have no idea...but trying to learn...so my code is below.. can any one please help me find the bug?
PHP Code: <?php my view is PHP Code: Hai <font color="<?= $color ?>" <? $name ?> </font>
Should be for CI 2+ and up:
PHP Code: class Hello extends CI_Controller What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
What is "var"? This is not javascript. This is php. You should at least know how to define variables in php. And what is this: "parent::Controller();"?
Website: http://avenir.ro
Munna, try this:
Controller: PHP Code: <?php View: PHP Code: Hai <span style="color: <?=$color?>;"><?=$name?></span>. I think, this is what you want. But I recommend you to learn actual HTML/CSS standards and OOP in PHP 5.4+ at first. Good luck.
Hi there
Change your controller as class Hello extends CI_Controller{ protected $name=''; //or can be public / private depending on your scope protected $color=''; public __construct(){ parent::__construct(); $this->name='test'; $this->color='red'; } function view() { $data['name']=$this->name; $data['color']=$this->color; $this->load->view('view',$data); } }//end hello class //then in your view change it to: Hai <font color="<?= $color ?>"> <?= $name ?> </font><!--Note the equal sign in front of name is needed --> OR Hai <font color="<?php echo $color ?>"><?php echo $name ?></font> This should work! |
Welcome Guest, Not a member yet? Register Sign In |