开发者

In PHP get arguments from inside a file called from outside

I got a function that calls a template file and need to check an argument specified inside the file:

Note: Only shortened examples over here

Inside config.php (in a class) - Edit: This should check if $echo is true and if it was set in a template.

// Edit:
function check_cb()
{
    // The {$echo} is meant to be from inside the template
    if ( $echo === TRUE AND $inside_template === TRUE )
        return $whatever = 'Using {$echo} in a callback & from inside template is not a开发者_运维百科llowed.'

    return $whatever = 'Check: ok';
}

Inside template.php (was called before check_cb)

$echo = FALSE;
$args = array(
     'type'         => 'input'
    ,'id'           => 'input_template_UID'
    ,'label'        => 'Input Template Label'
    ,'label_sep'    => false
    ,'opt_name'     => 'abc_xyz'
    ,'value'        => 'test value'
);
example_function( $args, $echo );

Inside part of another class

Question: How can I get arguments from inside a file? Is it even possible? Addition: I could also modify example_function(), but currently I haven't got any good ideas.


Just add this include_once("template.php"); in the start of your config.php file. Also add global $echo; inside your check_cb() function.

Something like this:

include_once("template.php");
function check_cb()
{
    global $echo;
    // The {$echo} is meant to be from inside the template
    if ( $echo === false )
        return $whatever = 'no'

    return $whatever = 'yes';
}

include_once("template.php") will basically make visible all of your functions, variables from template.php to config.php. But to use variables define outside of your function you musth use globalkeywor.

For more informations about global use have a look here and here for the include_once statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜