Welcome Guest, Not a member yet? Register   Sign In
Unable to get the model function parameter value
#1

[eluser]shadowchest[/eluser]
In a model file, I have a function functionname($param=false) { echo $param; }. In a controller file, I call the function by return $this->modelname->functionname(true); This should return a "true" value since I set the parameter to true, but still it returns false. Any idea?

I am using CI Version 1.7.3, by the way.
#2

[eluser]Unknown[/eluser]
well shadowchest, you most return $param to get the value you are expecting, echo function just print to the web server the string passed, but do not return a value.

Regards, W@lfrido
#3

[eluser]shadowchest[/eluser]
Yes, I tried return $param as well, but still it's FALSE.
#4

[eluser]shadowchest[/eluser]
Another one with same bug is this:

In the Model:

function functionname($param='test') {
if($param=='test') return 'This is a test.' else return 'This is not a test.';
}

In the Controller:

function functionname() {
$string = $this->modelname->functionname('nottest');
echo $string;
}

The function above should return "This is not a test.", but it returned "This is a test." string instead.
#5

[eluser]shadowchest[/eluser]
Found the problem already. There was just a model function call on my controller's constructor written by another programmer. Anyway, it's only I who understands my problem here though.

I conclude it is able to get the module function parameter value.

Mods, please close/delete this thread. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB