如何“全球化” PHP变量? [英] How to "globalize" PHP variables?

查看:95
本文介绍了如何“全球化” PHP变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ChangeApprovalInfo.php的页面 - 它有一个名为Row_Rendered的函数,如下所示:



$ p $函数Row_Rendered(){

//要查看字段类的属性,请使用:
// var_dump($ this->< FieldName>);

$ RecordOwner = $ this-> RequestUser-> CurrentValue;
echo $ RecordOwner;

$ / code>

回显$ RecordOwner可以获取我在另一个sql查询时需要的数据页面....



我有另一个页面叫ChangeApprovalEdit.php - 这个页面有

pre> <?php include_onceChangeApprovalinfo.php?>

位于文件顶部。



ChangeApprovalEdit.php有一个函数,我需要在ChangedApprovalInfo.php中定义的$ RecordOwner变量



如果我在ChangeApprovalEdit.php页面上添加echo $ RecordOwner我收到一个错误,说这是一个未知的变量。我的理解是我需要使其成为全球或某些此类业务。我对PHP知之甚少,而我正在编辑的页面又长又复杂。 (对我来说,至少)


  • 我需要做什么?我知道我提供的信息可能不足以回答这个问题。我甚至不知道甚至完全知道我需要问什么。如果需要更多信息,我会编辑并跟进。



文件的pastebin

  ChangeApprovalInfo.php = http://pastebin.com/bSRM1wwN 
ChangeApprovalEdit.php = http://pastebin.com/AStG9pqb

编辑:
将Row_Rendered更改为此似乎更有效。我无法看到哪里我可以稍后回应这个变量......但我正在得到这个地方......

  function Row_Rendered(){
//要查看字段类的属性,请使用:
// var_dump($ this->< FieldName>);
$ GLOBALS ['RecordOwner'] = $ this-> RequestUser-> CurrentValue;


解决方案

事情:

首先,您可以从函数中返回 $ RecordOwner ,并将其值存储在一个变量中。

 函数Row_Rendered(){

//查看字段的属性类,使用:
// var_dump($ this->< FieldName>);

$ RecordOwner = $ this-> RequestUser-> CurrentValue;
echo $ RecordOwner;

返回$ RecordOwner;
}

//调用函数时将其存储在一个变量中。
$ RecordOwner = Row_Rendered();

或者,您可以在函数内使它成为全局的:

 函数Row_Rendered(){

//要查看字段类的属性,请使用:
// var_dump($ this-> ;<字段名>);

$ GLOBALS ['RecordOwner'] = $ this-> RequestUser-> CurrentValue;
echo $ GLOBALS ['RecordOwner'];
}


I have a page named ChangeApprovalInfo.php - It has a function called Row_Rendered as follows;

function Row_Rendered() {

    // To view properties of field class, use:
    //var_dump($this-><FieldName>);

    $RecordOwner = $this->RequestUser->CurrentValue;  
        echo $RecordOwner;
} 

Echoing $RecordOwner gets me the data I will need for a sql query on another page....

I have another page called ChangeApprovalEdit.php - This page has

<?php include_once "ChangeApprovalinfo.php" ?>

at the top of the file.

ChangeApprovalEdit.php has a function where I need the $RecordOwner variable as defined in ChangedApprovalInfo.php

If I add "echo $RecordOwner" on the ChangeApprovalEdit.php page, I get an error saying it's an unknown variable. My understanding is that I need to "make it global" or some such business. I know very little about PHP and the pages I am editing are long and complex. (to me, at least)

  • What do I need to do? I know that the information I have provided might not be enough to answer the question. I don't know enough to even know exactly what I need to ask. If more information is needed, I will edit and follow up.

pastebin of the files

ChangeApprovalInfo.php = http://pastebin.com/bSRM1wwN
ChangeApprovalEdit.php = http://pastebin.com/AStG9pqb

EDIT: Changing Row_Rendered to this seems to be more effective. I'm having trouble seeing WHERE I can later echo this variable... but I'm getting somewhere with this...

function Row_Rendered() {
    // To view properties of field class, use:
    //var_dump($this-><FieldName>);
    $GLOBALS['RecordOwner'] = $this->RequestUser->CurrentValue;  
} 

解决方案

You can do a couple of things:

First, you can return $RecordOwner from the function, and store its value in a variable. This method is usually preferred.

function Row_Rendered() {

    // To view properties of field class, use:
    //var_dump($this-><FieldName>);

    $RecordOwner = $this->RequestUser->CurrentValue;  
        echo $RecordOwner;

    return $RecordOwner;
} 

// Store it in a variable when calling the function.
$RecordOwner = Row_Rendered();

Or, you can make it global inside the function:

function Row_Rendered() {

    // To view properties of field class, use:
    //var_dump($this-><FieldName>);

    $GLOBALS['RecordOwner'] = $this->RequestUser->CurrentValue;  
        echo $GLOBALS['RecordOwner'];
} 

这篇关于如何“全球化” PHP变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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