Dunque cominciamo dalle basi:
Quando scrivo:
Codice PHP:$venues = \woo\domain\Venue::findAll();
Chiamo findAll() e istanzio Venue ovvero eseguo il suo costruttore oltre che al metodo oppure chiamo solamente findAll()?
Dunque cominciamo dalle basi:
Quando scrivo:
Codice PHP:$venues = \woo\domain\Venue::findAll();
Chiamo findAll() e istanzio Venue ovvero eseguo il suo costruttore oltre che al metodo oppure chiamo solamente findAll()?
Più pratica in futuro...
Codice PHP:<?php
class Prova {
function __construct(){
print "non";
}
static function findAll(){
print "ho capito!";
}
}
$r = Prova::findAll();
print "<br>";
$r = new Prova();
print " ho fatto questo errore! azz... (:";
print "<br>dove ho sbagliato dunque?";
Più pratica in futuro...
certo che lo so ma penso che non troverò risposte utli su questo forum perché nessuno scaricherebbe il file dal link che ho riportato sopra e nessuno si metterebbe a leggerlo...
Luca sapresti consigliarmi un plugin per fare il debug del software su Eclipse in modo da farmi aiutare dal software nel capire i passaggi da un file ad un altro? Non so se hai mai usato Matlab ma una cosa simile alle famose freccette che indicano la riga in esecuzione...
Più pratica in futuro...
Perché ho seguito tutto il procedimento e non capisco questo getName() riesca a stampare le stringhe:
bob
The Eyeball Inn
The Eyeball Inn
The Eyeball Inn
The Eyeball Inn
e non ho più idea di dove andare a cercare...
Ora riprovo da capo... forse ho trascurato qualcosa...
se hai voglia di leggerlo qui trovi i codici:
http://www.apress.com/9781430260318
Il file che sto vedendo è questo:
9781430260318_Chapter_12_Code/listing12.08.php
![]()
Più pratica in futuro...
Ho rivisto tutto l'esempio ma continua ad esserci qualcosa che mi sfugge. Non capisco questo getName() da dove venga preso.
I passaggi da un file ad un altro sono i seguenti:
listing12.08.php -> Venue.php -> DomainObject.php -> HelperFactory.php -> VenueMapper.php -> Mapper.php -> Registry.php -> Mapper.php -> VenueMapper.php -> HelperFactory.php -> DomainObject.php -> Venue.php -> VenueMapper.php -> Mapper.php -> VenueMapper.php -> Mapper.php -> VenueMapper.php -> Collections.php -> Collection.php -> Mapper.php -> Venue.php -> listing12.08.php
Quando si torna in listing12.08.php si ottiene un oggetto di tipo woo\mapper\SpaceCollection salvato in $venues che non ha getName() però nel codice php leggo:
e funziona. Come è possibile?Codice PHP:<?php print $venue->getName(); ?><br />
So a cosa state pensando che $venues sia un array, ebbene no, ho controllato è un oggetto quindi il ciclo for itera una volta sola.
Con la speranza che vogliate darmi una mano vi elenco qui di seguito tutte ma proprio tutte le classi interessate con la speranza che sappiate dirmi dove sbaglio. Ehh... lo so ci vogliono 15 minuti e un pezzo di carta... Io l'ho rifatto 3 volte ed arrivo sempre alla stessa incognita.
Più pratica in futuro...
listing12.08.php
Codice PHP:<?php
require_once("woo/domain/Venue.php");
try {
$venues = \woo\domain\Venue::findAll();
} catch ( Exception $e ) {
include( 'error.php' );
exit(0);
}
// default page follows
?>
<html>
<head>
<title>Venues</title>
</head>
<body>
<h1>Venues</h1>
<?php foreach( $venues as $venue ) { ?>
<?php print $venue->getName(); ?><br />
<?php } ?>
</body>
</html>
Più pratica in futuro...
Venue.php
Codice PHP:<?php
namespace woo\domain;
require_once( "woo/domain/DomainObject.php" );
class Venue extends DomainObject {
private $name;
private $spaces;
function __construct( $id=null, $name=null ) {
$this->name = $name;
parent::__construct( $id );
}
function setSpaces( SpaceCollection $spaces ) {
$this->spaces = $spaces;
}
function getSpaces() {
if ( ! isset( $this->spaces ) ) {
$finder = self::getFinder( 'woo\\domain\\Space' );
$this->spaces = $finder->findByVenue( $this->getId() );
//$this->spaces = self::getCollection("woo\\domain\\Space");
}
return $this->spaces;
}
function addSpace( Space $space ) {
$this->getSpaces()->add( $space );
$space->setVenue( $this );
}
function setName( $name_s ) {
$this->name = $name_s;
$this->markDirty();
}
function getName( ) {
return $this->name;
}
static function findAll() {
$finder = self::getFinder( __CLASS__ );
return $finder->findAll();
}
static function find( $id ) {
$finder = self::getFinder( __CLASS__ );
return $finder->find( $id );
}
}
?>
Più pratica in futuro...
DomainObject.php
Codice PHP:<?php
namespace woo\domain;
require_once( "woo/domain/Collections.php" );
require_once( "woo/domain/ObjectWatcher.php" );
require_once( "woo/domain/HelperFactory.php" );
abstract class DomainObject {
private $id = -1;
function __construct( $id=null ) {
if ( is_null( $id ) ) {
$this->markNew();
} else {
$this->id = $id;
}
}
function markNew() {
ObjectWatcher::addNew( $this );
}
function markDeleted() {
ObjectWatcher::addDelete( $this );
}
function markDirty() {
ObjectWatcher::addDirty( $this );
}
function markClean() {
ObjectWatcher::addClean( $this );
}
function getId( ) {
return $this->id;
}
static function getCollection( $type ) {
return HelperFactory::getCollection( $type );
}
function collection() {
return self::getCollection( get_class( $this ) );
}
function finder() {
return self::getFinder( get_class( $this ) );
}
static function getFinder( $type ) {
return HelperFactory::getFinder( $type );
}
function setId( $id ) {
$this->id = $id;
}
function __clone() {
$this->id = -1;
}
}
?>
Più pratica in futuro...