Accessing attributes and methods of instantiated class in another class

4

In front of the structure below:

  • class View
  • class Controller
    • new View ()
  • class controllerUser extends Controller
    • public $ user;

as $usuario access from View?

    
asked by anonymous 17.10.2015 / 19:02

2 answers

3

You can use namespace to use classes in other files.

use RaizDaPasta\pastaDaClasse\Classe;

Within your file where you make use instantiate a new object and use the function you want

    
18.10.2015 / 17:25
0

I do not really understand what you want to do, but I think it should look something like this:

<?php

class Apresentar
{
    public function __construct(ControllerUsuario $usuario)
    {
        echo $usuario->getUsuario();
    }
}

class ControllerUsuario
{
    private $usuario = 'Fábio';

    public function getUsuario()
    {
        return $this->usuario;
    }
}

new Apresentar(new ControllerUsuario);
    
17.10.2015 / 19:36