我一直在尝试使用带有laravel的collivery包。但是,当我尝试使用它时,我得到标题中的错误。我将如何非静态地调用该类。
这就是我想说的。
public function getTowns( $country = "ZAF", $province = null )
{
if ( ( $this->check_cache == 2 ) && is_null( $province ) && $this->cache->has( 'collivery.towns.'. $country ) ) {
return $this->cache->get( 'collivery.towns.'.$country );
} elseif ( ( $this->check_cache == 2 ) && ! is_null( $province ) && $this->cache->has( 'collivery.towns.'. $country .'.'. $province ) ) {
return $this->cache->get( 'collivery.towns.'.$country.'.'.$province );
} else {
try {
$result = $this->client()->get_towns( $this->token, $country, $province );
} catch ( SoapFault $e ) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['towns'] ) ) {
if ( is_null( $province ) ) {
if ( $this->check_cache != 0 ) $this->cache->put( 'collivery.towns.'. $country, $result['towns'], 60*24 );
} else {
if ( $this->check_cache != 0 ) $this->cache->put( 'collivery.towns.'. $country .'.'. $province, $result['towns'], 60*24 );
}
return $result['towns'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No result returned.' );
return false;
}
}
}
答案 0 :(得分:0)
您需要创建要在控制器中访问的Collivery类的实例。您可以尝试以下代码
$config = array(
'app_name' => 'Default App Name', // Application Name
'app_version' => '0.0.1', // Application Version
'app_host' => '', // Framework/CMS name and version, eg 'Wordpress 3.8.1 WooCommerce 2.0.20' / 'Joomla! 2.5.17 VirtueMart 2.0.26d'
'app_url' => '', // URL your site is hosted on
'user_email' => 'demo@collivery.co.za',
'user_password' => 'demo',
'demo' => false,
);
$collivery = new \Mds\Collivery( $config );
$towns = $collivery->getTowns();
dump( $towns );`