CodeIgniter Forums
Unable to get the model function parameter value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Unable to get the model function parameter value (/showthread.php?tid=43394)



Unable to get the model function parameter value - El Forum - 07-09-2011

[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.


Unable to get the model function parameter value - El Forum - 07-09-2011

[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


Unable to get the model function parameter value - El Forum - 07-09-2011

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


Unable to get the model function parameter value - El Forum - 07-09-2011

[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.


Unable to get the model function parameter value - El Forum - 07-10-2011

[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!