Closed luchothoma closed 6 years ago
Your typehints are for the classes (Mapper, Entity), but they should be for the interfaces (MapperInterface, EntityInterface):
class Notificacion extends \Spot\Entity{
// ...
public static function relations(MapperInterface $mapper, EntityInterface $entity){
// ...
}
}
Really thanks to your hint !!!
Finally I have to do this:
public static function relations(\Spot\MapperInterface $mapper, \Spot\EntityInterface $entity)
I suppose that If i put use \Spot; at the beginning of file, I will write exactly what you answer to me, so I should use it like that ?
Another thing, I am new to Spot but I like it, but this "obvious" problem can be "fix" it, if in the documentation where like you explane and not as it is now. [http://phpdatamapper.com/docs/relations/](Spot Doc Relations)
If you put
use Spot\MapperInterface;
use Spot\EntityInterface;
at the top of the file, you don't need the full classname. The PHP documentation has excellent info on namespaces
I've sent a PR for the docs :)
This is my actual code: I have 2 clases LocalDeComida (like a restaurante) that has many Notificacion (notifications)
LocalDeComidaEntity.php `<?php namespace Entity; class LocalDeComida extends \Spot\Entity { protected static $mapper = 'Entity\Mapper\Reporte'; protected static $table = 'casa_de_comida';
} ?>`
NotificacionEntity.php `<?php namespace Entity; class Notificacion extends \Spot\Entity { protected static $mapper = 'Entity\Mapper\Notificacion'; protected static $table = 'notificacion';
} // This is the 27 line of the file ?>`
And when I try to use it as here: $localDeComidaMapper->get(1)->notifications() Throws this exception Fatal error: Declaration of Entity\Notificacion::relations() must be compatible with Spot\EntityInterface::relations(Spot\MapperInterface $mapper, Spot\EntityInterface $entity) in NotificacionEntity.php on line 27
Can you give me some advice please ?