【发布时间】:2014-09-20 07:25:15
【问题描述】:
我有一个从数据库中获取值并返回的函数。当我回显时,该值确实存在。但返回值为null;
public static function getCountryCode($country) {
$country = (int) $country;
$x = Country::where('id', $country)->get();
$country_code = '';
foreach($x as $row)
$country_code = $row->alpha_2;
//return 'bd';
echo $country_code;
return $country_code;
}
不知道那里出了什么问题。这是一个 laravel 项目。
调用此方法的函数
public function countryselect()
{
$country_id = HomeController::detectCountry();
$country_code = SiteController::getCountryCode($country_id);
var_dump($country_code);
return View::make('Layout.countryselect', compact('country_id', 'country_code'));
}
【问题讨论】:
-
你能显示调用这个方法的代码吗?
-
public function countryselect() { $country_id = HomeController::detectCountry(); $country_code = SiteController::getCountryCode($country_id); var_dump($country_code); return View::make('Layout.countryselect', compact('country_id', 'country_code')); } -
如果将其添加到问题中会更容易格式化。那里有一个待定的编辑,但也需要引入。
-
这是用来调用@bcmcfc的函数
标签: php function laravel-4 null