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?
$_POST vs. 'post'
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Forum rules
-
- Joomla! Apprentice
- Posts: 41
- Joined: Sat Dec 15, 2007 3:02 pm
- Location: Washington DC Metro
Re: $_POST vs. 'post'
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);
Denise
Re: $_POST vs. 'post'
Thanks for the reply, is there really a difference (other than syntatically of course) betweenthese two methods?
- Rogue4ngel
- Joomla! Enthusiast
- Posts: 199
- Joined: Sun Nov 26, 2006 10:46 pm
- Location: New York
Re: $_POST vs. 'post'
I believe yours is passing the value of the string, the other is passing a reference to the value.
If you're not a part of the solution, you're a part of the problem.
- louis.landry
- Joomla! Enthusiast
- Posts: 101
- Joined: Wed Aug 17, 2005 11:03 pm
- Location: New Orleans, Louisiana
- Contact:
Re: $_POST vs. 'post'
The correct way to do what you are wanting to do is:
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
Code: Select all
$this->assign( 'name', JRequest::getVar( 'name','', 'post', 'string') );
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
Project Manager :: Developer
http://www.webimagery.net
A hacker does for love what others would not do for money.
http://www.webimagery.net
A hacker does for love what others would not do for money.
- Rogue4ngel
- Joomla! Enthusiast
- Posts: 199
- Joined: Sun Nov 26, 2006 10:46 pm
- Location: New York
Re: $_POST vs. 'post'
Thanks Louis. Always helps to get it 'from the source'.
If you're not a part of the solution, you're a part of the problem.