Using or not using 'assign' and 'assignref'

973 views
Skip to first unread message

Richard

unread,
Mar 21, 2012, 2:24:10 PM3/21/12
to joomla-de...@googlegroups.com
In J1.5 examples and books, assign() and assignref() are used to pass data from a view into the layout.
I noticed that these seem to be replaced in J1.6 and above by just adding the data to the view object.
Are assign and assignref needed any more and if so, under what circumstances should I use them?

Hannes Papenberg

unread,
Mar 21, 2012, 2:54:04 PM3/21/12
to joomla-de...@googlegroups.com
assign() and assignRef() are not needed anymore, since Joomla 1.6/2.5
requires at least PHP 5.2, which has far better memory management, which
is the main reason why those two methods were introduced. Those two
methods are assigning the variables by reference and not by value. PHP4
by default used assign by value, while PHP5 (when using objects) uses
assign by reference.

Bottom line: You don't need assign() and assignRef() anymore.

Hannes

> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To view this discussion on the web, visit
> https://groups.google.com/d/msg/joomla-dev-general/-/MDQTvTtWE_wJ.
> To post to this group, send an email to
> joomla-de...@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-gene...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Rouven Weßling

unread,
Mar 21, 2012, 3:22:21 PM3/21/12
to joomla-de...@googlegroups.com
If anyone's bored, I think a patch that gets rid of all calls to assign() and assignRef() would be awesome. They're not gonna be around forever and than we don't have to worry about them down the road.

Rouven

Daniel Dimitrov

unread,
Aug 4, 2012, 8:07:24 AM8/4/12
to joomla-de...@googlegroups.com
Just use $this->variable = $something; in your view.html.php and it will be available in the layout.
Cheers,
Daniel

On Saturday, August 4, 2012 5:20:36 AM UTC+2, Xerosigma wrote:
How to we pass vars to the display then? I can't seem to get default.php to display mine. The print_r inside of the view prints the data just fine. O.O

Nestor Ledon

unread,
Aug 4, 2012, 9:02:29 PM8/4/12
to joomla-de...@googlegroups.com
Sweet. Got it working thanks.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/7Tp_7WQcL0YJ.

piotr_cz

unread,
Nov 17, 2012, 9:56:35 AM11/17/12
to joomla-de...@googlegroups.com
Just wondering, all core view classes ('view.html.php') in CMS 2.5 have these variables ($data, $item) protected and thus cannot be set directly from controller.
That's what Rouven was speaking about? To change to

View:
class HelloworldViewHello
{
  public $data;
  // ...
}

Controller:
$view->data = $data;

?
Reply all
Reply to author
Forward
0 new messages