Welcome Guest, Not a member yet? Register   Sign In
Problem accessing variable from function in plugin
#1

[eluser]Unknown[/eluser]
Hello, the answer is probably very obvious but I can't seem to find it. I have the following plugin, in system/applications/plugins/rounded_pi.php
Code:
function rounded($number) {
    global $row_background;
    $divided = $number / 2;
    if (strstr($divided, ".")) {
    $row_background = "even";
    
    } else {
    $row_background = "odd";
    }
}

and in my controller,
Code:
function Participants() {
        parent::Controller();
        $this->load->plugin('rounded');
}

No matter what I've tried I can't access $row_background in my view- (I did add "return $row_background;" but that didn't work either) I know the function is loading, if I add echo $row_background; it shows up each time the function is called, but outside the function I get "undefined variable $row_background".

For what it's worth, the function doesn't return anything even if I place it in the view- it's worked in past non-CI projects as a function called from an include file- but this is my first time inside CI, and I'm wondering if there's something that I'm missing specific to CI.

Thanks-
#2

[eluser]eoinmcg[/eluser]
probably easiest to return it to the controller

Code:
$data['row_background'] = $this->load->plugin('rounded');




Theme © iAndrew 2016 - Forum software by © MyBB