Use of variables from a file called with Include

0

Again needing your help, this time I need to use some variables that are inside a file ComputerWork.php which I send to call from proyectos.php by means of a include These variables I need to place them within a array but I do not know how to extract them from their source file. I leave the code waiting for you to understand and can help me:

ComputerWork.php

<?php
if (!isset($conex)) {
    //Código...
}
if (filter_input(INPUT_GET, 'f') !== null)
    $f = filter_input(INPUT_GET, 'f');
if (filter_input(INPUT_GET, 'id') !== null)
    $id = filter_input(INPUT_GET, 'id');
if ($puedeEditar) {
    //Código...
    if($f == 'n'){
        //Código...
    }
    elseif ($f == 'n2') {
//VARIABLES QUE NECESITO - $personaID, $rol, $tipoRH...
        $rol = 5;
        $empleado_id = $us_id =  0;
        $personaID = filter_input(INPUT_GET, 'personaID'); //$personaID
        if(filter_input(INPUT_GET, 'rol') !== null)
            $rol = filter_input(INPUT_GET, 'rol'); //rol
        $tipoRH = filter_input(INPUT_GET, 'tipo'); //tipoRH
        if($tipoRH == 1){
            //Código...
        }
        else{
            //Código...
        }
        if($us_id > 0){
            //Código...
        }
    }
    elseif($f == 'e'){
        //Código...
    }
    elseif($f == 'e2'){
//VARIABLES QUE NECESITO - $idEmp, $rol, $activo...
        $idEmp = filter_input(INPUT_GET, 'idEmp'); //idEmp
        $rol = filter_input(INPUT_GET, 'rol'); //$rol
        $activo = filter_input(INPUT_GET, 'activo'); //$activo
        if(!empty($rol) && !empty($activo)){
            //Código...
        }
    }
}
?>

proyectos.php

<?php
if (!$tieneAcceso) {
    //Código...
}
if (!isset($conex)) $conex = new SafeMySQL ();
if ($puedeEditar) {
    //Código...
}
if (filter_input(INPUT_GET, 'op1') !== null) {
    //Código...
}
if (filter_input(INPUT_GET, 'op2') !== null) {
    //Código...
}
if ($opcion1 == 'newPr' && $puedeEditar) {
    //Código...
}
//ESTA PARTE DE AQUÍ ES EL CONTROLADOR...
elseif ($opcion1 == 'edit') {
    if (null !== filter_input(INPUT_GET, 'id')) {
        //Código...
    }
    if (empty($nProyecto))
        die('Se requiere clave de registro');
    if($idObtenido != $nProyecto){
        //Código...
    }
    else {
        //Código...
    }
    if (filter_input(INPUT_POST, 'proyecto') !== null) {
        if (!$puedeEditar) {
            //Código...
        }
        $proyecto2 = filter_input(INPUT_POST, 'proyecto', FILTER_SANITIZE_SPECIAL_CHARS);
        $cliente_id2 = filter_input(INPUT_POST, 'cliente_id');
        $estatus2 = filter_input(INPUT_POST, 'estatus');
        $objetivo2 = filter_input(INPUT_POST, 'objetivo');
        $color2 = filter_input(INPUT_POST, 'color');
//ARRAY EN EL QUE QUIERO AGREGAR LAS VARIABLES OBTENIDAS DEL ARCHIVO equipoTrabajo.php - $registro
        $registro = array(); //$registro
        $registro['cliente_id'] = $cliente_id2;
        $registro['estatus'] = $estatus2;
        $registro['objetivo'] = $objetivo2;
        $registro['color'] = $color2;
        if (!empty($proyecto2)) {
            //Código...
        }
        if ($result === true) {
            //Código...
        }
        else {
            //Código...
        }
    }
//ESTA PARTE DE AQUÍ ES LA VISTA...
    if($puedeEditar){
        //Código...
    }
    if($puedeElim){
        //Código...
    }
    if($_SESSION['proy_p2'] > 0){
        //Código...
    }
    $idTab = 'eProy';
    iniModulo("Proyectos - $proyecto");
    abreFormTab($idTab, $aTabs, $elpost);
    abreTab($idTab, 1);
    abreBloque('Datos generales');
    label1('*', 'Departamento', $_Depto->getName());
    inputText('<', 'Proyecto', 'proyecto', $proyecto, '', array('placeholder' => 'Proyecto', 'required' => ''));
    showSelect('>', 'Estatus', 'estatus', $estatus, $estatusProyecto, 'Seleccione el estatus del Proyecto', $propC1);
    showSelect('<', 'Cliente', 'cliente_id', $cliente_id, $aClientes, 'Seleccionar Cliente', $propC1);
    inputText('>', 'Color', 'color', $color, '', array('placeholder' => 'Color', 'id'=>'colorpicker'));
    textArea('*', 'objetivo', 'Objetivo', $objetivo, 'Objetivo del proyecto', $pCDetalle);
    cierraBloque();
    cierraTab();
    $id = $nProyecto;
    abreTab($idTab, 2);
    abreBloque('Equipo de trabajo');
    abreDiv('divProET');
//INCLUDE CON EL CUAL MANDO A LLAMAR EL ARCHIVO equipoTrabajo.php...
    include ('equipoTrabajo.php');
    cierraDiv();
    cierraBloque();
    cierraTab();
    if($_SESSION['proy_p2'] > 0){
        abreTab($idTab, 3);
        abreBloque('Lista de archivos');
        abreDiv('divAdjP');
        require 'proy_adj.php';
        cierraDiv();
        cierraBloque();
        cierraTab();
    }
    cierraFormTab($btnEnviar, $urlList, '', $btnElimP);
}
?>

The files are much more extensive but I tried to remove the parts that I considered were not necessary.

The variables I need to add in array are to be sent as a parameter to a function that the Project edits and in turn records changes in a history.

These files are not mine but I am working on them, they have been modified over a few years, that's why structured programming is part of POO.

Thank you in advance (:

    
asked by Paloma Alvarado 22.08.2017 в 18:04
source

1 answer

1

The include can be included before this part of your code, assuming that $cliente_id2 is a variable defined in equipoTrabajo.php , (to name a variable).

Your file:

//ARRAY EN EL QUE QUIERO AGREGAR LAS VARIABLES OBTENIDAS DEL ARCHIVO equipoTrabajo.php - $registro

    $registro = array(); //$registro
    $registro['cliente_id'] = $cliente_id2;
    $registro['estatus'] = $estatus2;
    $registro['objetivo'] = $objetivo2;
    $registro['color'] = $color2;

How you could implement it:

include ('equipoTrabajo.php');
//ARRAY EN EL QUE QUIERO AGREGAR LAS VARIABLES OBTENIDAS DEL ARCHIVO equipoTrabajo.php - $registro

    $registro = array(); //$registro
    $registro['cliente_id'] = $cliente_id2;
    $registro['estatus'] = $estatus2;
    $registro['objetivo'] = $objetivo2;
    $registro['color'] = $color2;

In this way you can use the variables, functions that are defined in the included file.

  


Note
The PHP interpreter reads the files line by line for this   reason it is advisable to include the files before implementing their   functions or variables, in a contrary way it will throw indefinite variable

    
answered by 22.08.2017 в 19:12