Reputation: 1959
class Chan extends CI_Controller
{
public function index()
{
$this->load->helper('chan');
$this->load->view('chan', ['age' => 35]);
}
}
function getValue($name = null) {
global ${$name};
if (isset(${$name})) {
return ${$name};
}
}
<?php echo getValue('age'); ?>
I want to use the same view to do the insert and update stuff, when you doing insert method will be no data passing to the view, we can do something like
<input name="age" value="<?php echo isset($age) ? $age : ''; ?>">
But for me, I feel it's too ugly, therefore I want to build a helper called getValue
to do this, but I can't get the value was set or not in the helper, how to make this function come true.
Upvotes: 1
Views: 48
Reputation: 306
try this one:
function getValue(&$variable, $default_value = '') {
return isset($variable) ? $variable : $default_value;
}
Upvotes: 1