Welcome Guest, Not a member yet? Register   Sign In
raw/flat versus codeIgniter
#1

[eluser]ranjitbd[/eluser]
Code:
// it is a code block in view page inside views folder. but its not showing the $x value

<?php

$x = "its";    

function show_value()
{
    global $x ;
    echo $x." not working";
}
show_value();

// output: not working
// but it should be
// output: its not working

?>


// but if it is a raw/flat php coding without any framework
// the output: its not working  
// which is correct

//so why the correct output not showing with codeigniter inside a view page?
#2

[eluser]bigtony[/eluser]
You should not be defining functions within a view. Views are just for presenting data, so the only PHP code in them should be stuff directly concerned with how it looks (htmlentities(), number_format(), foreach loops through recordsets, that kind of thing).

Instead, move your variable setup & functions to your controller and then pass that data into the view, then just echo it from there.




Theme © iAndrew 2016 - Forum software by © MyBB