我没有使用laravel或任何框架,我正在遵循O 'reilly modern php book中的教程。我正在使用php版本7;
使用traits时出现此错误
Fatal error: Trait 'Geocodable' not found in /Applications/MAMP/htdocs/eli9/RetailStore.php on line 5
这是以下代码
Geocodable.php
<?php
trait Geocodable{
protected $address;
protected $geocoder;
protected $geocoderResult;
public function setGeocoder(\Geocoder\Geocoder $geocoder)
{
$this->geocoder = $geocoder;
}
public function setAddress($address)
{
$this->address = $address;
}
public function getLatitude()
{
if(!isset($this->geocoderResult)){
$this->geocodeAddress();
}
return $this->geocoderResult->first()->getLatitude();
}
public function getLongitude()
{
if(!isset($this->geocoderResult)){
$this->geocodeAddress();
}
return $this->geocoderResult->first()->getLongitude();
}
public function getcodeAddress()
{
$this->geocoderResult = $this->gecoder->geocode($this->address);
return true;
}
}
RetailStore.php
<?php
class RetailStore
{
use Geocodable;
}