Page 1 of 1

$_POST vs. 'post'

Posted: Thu Mar 13, 2008 12:55 pm
by shahpound
Hi,

In a component I created, depending on the system, visitors will get errors from this:

$this->assignRef( 'name', JRequest::getVar( 'name','', 'post', 'string') );

but not from this:

$this->assignRef( 'name', JRequest::getVar( 'name','', $_POST, 'string') );

The error is from PHP:

*Fatal error*: Only variables can be passed by reference in ... [filename]

Any ideas why this happens and what the difference is?

Re: $_POST vs. 'post'

Posted: Sat Mar 15, 2008 3:17 pm
by radiant_tech
Instead of including the getVar method within the assignRef method, set the variable first and then pass the variable to assignRef(). Such as

Code: Select all

$name = JRequest::getVar( 'name','', 'post', 'string');
$this->assignRef('name', $name);

Re: $_POST vs. 'post'

Posted: Sat Mar 15, 2008 4:20 pm
by shahpound
Thanks for the reply, is there really a difference (other than syntatically of course) betweenthese two methods?

Re: $_POST vs. 'post'

Posted: Sat Mar 15, 2008 9:13 pm
by Rogue4ngel
I believe yours is passing the value of the string, the other is passing a reference to the value.

Re: $_POST vs. 'post'

Posted: Sat Mar 15, 2008 9:29 pm
by louis.landry
The correct way to do what you are wanting to do is:

Code: Select all

$this->assign( 'name', JRequest::getVar( 'name','', 'post', 'string') );
http://api.joomla.org/Joomla-Framework/ ... tml#assign

You cannot assign a value by reference... you may only assign a reference by reference.

JView::assignRef() assigns by reference.
JRequest::getVar() returns a value.

Louis

Re: $_POST vs. 'post'

Posted: Sat Mar 15, 2008 9:32 pm
by Rogue4ngel
Thanks Louis. Always helps to get it 'from the source'.