Ver Mensaje Individual
  #5 (permalink)  
Antiguo 13/03/2012, 13:47
loogys
 
Fecha de Ingreso: marzo-2012
Mensajes: 9
Antigüedad: 12 años, 1 mes
Puntos: 0
Respuesta: Por que no funciona esta interfaz?

Si eso si lo entiendo... mira te lo voy a explicar mas claramente...

Esto me funciona muy bien:

index.php

Código PHP:
<?php

require_once 'pro.php';
require_once 
'pantalla.php';

class 
index
{
    public function 
run()
    {
        
$array = array('animal' => '1414''stat' => 'Gestante');        
        
        
$pantalla = new pantalla();
        
$txt = new texto($array'animales');
        
//$txt->setNombre('Maitee');
        
$txt->setTable('tratamientos');
        
$pantalla->showIt($txt);
    }
}

$haber = new index();
$haber->run();
pro.php
Código PHP:
<?php
require_once 'interfaceShow.php';

class 
texto implements interfaceShow
{
    private 
$_arrayData = array(), $_table$_mensaje;
    
    public function 
__construct($array$table)
    {
        
$this->_arrayData $array;
        
$this->_table $table;
    }
    public function 
show()
    {
        
$nuevo '';
        foreach(
$this->_arrayData as $clave => $valor){
            
$nuevo .= $clave." -> ".$valor."<br/>";
        }
        return 
$nuevo."<br/> Para la tabla ".$this->_table;;
    }
    public function 
setNombre($nombre)
    {
        
$this->_nombre $nombre;
    }
    public function 
setTable($table)
    {
        
$this->_table $table;
    }
    public function 
__toString()
    {
        return 
show();
    }
}
pantalla.php

Código PHP:
<?php
require_once 'interfaceShow.php';

class 
pantalla
{
    public function 
showIt(interfaceShow $mensaje)
    {
        echo 
$mensaje->show();
    }
}

<?php

Código PHP:
interface interfaceShow
{
    public function 
show();
    public function 
setNombre($nombre);
    public function 
setTable($table);


Si te das cuenta en la clase pantalla tengo el metodo showit y ahi mando llamar al metodo show() no le paso nada de variables y me imprime el mensaje... yo quiero usar solo show($mensaje) desde index y no funciona...

quiero algo como esto pero no funciona:

index.php
Código PHP:
<?php

require_once 'pro.php';
require_once 
'pantalla.php';

class 
index
{
    public function 
run()
    {
        
$array = array('animal' => '1414''stat' => 'Gestante');        
        
        
$pantalla = new pantalla();
        
$txt = new texto();
        
$txt->show($array,'usuarios');
        
$pantalla->showIt($txt);
    }
}

$haber = new index();
$haber->run();

Aun mas resumido... con los 4 archivos que tengo como puedo desde index usar el metodo show y mostrarlo en pantalla...