什么是joomla 2.5中的assignRef()函数 [英] Whats is assignRef() function in joomla 2.5

查看:96
本文介绍了什么是joomla 2.5中的assignRef()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何在joomla 2.5中开发自定义组件,而在第一步我被困住了,我想知道什么是use AssignRef()函数,有关更多信息,请参见

i am trying to understand about how to develop custom components in joomla 2.5 and on the very first step i get stuck and i want to know what is the use assignRef() function and for more info click here

<?php
/**
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
 * @license    GNU/GPL
*/

// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */

class HelloViewHello extends JView
{
    function display($tpl = null)
    {
        $greeting = "Hello World!";
        $this->assignRef( 'greeting', $greeting );

        parent::display($tpl);
    }
}

在assignRef()函数中,第一个参数用作变量而不是值,因为如果我将其值更改为其他值,则它无法显示$ greeting的值:-

In assignRef() function, the first parameter acts as variable not a value because if i am changing it's value to some other thing then it is not able to showing the value of $greeting:-

http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1 * @许可证GNU/GPL */

http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1 * @license GNU/GPL */

// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */

class HelloViewHello extends JView
{
    function display($tpl = null)
    {
        $greeting = "Hello World!";
        $this->assignRef( 'greeting123', $greeting );

        parent::display($tpl);
    }
}

然后在site/views/hello/tmpl/default.php中,如果我这样写,那么它向我显示了正确的答案:-

then in site/views/hello/tmpl/default.php, if i write like these then it is showing me the correct answer:-

<?php

// No direct access

defined('_JEXEC') or die('Restricted access'); ?>
<h1><?php echo $this->greeting123; ?></h1>

那么结果将是:---- Hello world

Then the result will be:---- Hello world

我知道对您来说这是一个简单或天真的问题,但对我来说这是我自己的开发领域新时代的开始.

I know that for you it's been a simple or a naive question but for me it's the beginning of a new era in my own development field..Anything will be appreciated the most..

推荐答案

在Joomla 1.5中,有两个函数assign()assignRef()用于将数据从视图传递到布局.但是在Joomla 1.6及更高版本中因为 Joomla 1.6/2.5 至少需要 PHP 5.2 ,所以它具有更好的内存管理,这是主要原因.介绍了这两种方法.那两个 方法是通过引用而不是值来分配变量. PHP4 默认情况下使用按值分配,而 PHP5 (使用对象时)使用 通过引用分配.

In Joomla 1.5 ,There are two function assign() and assignRef() are used to pass data from a view into the layout.But from Joomla 1.6 and above it just done by adding the data to the view object.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.

如果您使用的是Joomla最新版本,则只需输入

IF you are using Joomla latest version you can just do it by putting

$this->variable = $something;

view.html.php中,它将在布局中可用.

in your view.html.php and it will be available in the layout.

这篇关于什么是joomla 2.5中的assignRef()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆