我有点卡住了,我有很多 if else 语句处理,我需要在更多的无页面中使用它,所以在视图中处理它不是一个好主意(并且阅读它不是一个好主意)
所以我被困住了,我有 2 张桌子。
user
users_details
User table
存储基本登录信息,并且用户details
具有以下字段
user_id
first_name
last_name
company
location
experience
compensation
about
gender
year
day
month
profile_image
我的关系
用户模型
public function detail()
{
return $this->has_one('Detail');
}
详细型号
public function user()
{
return $this->belongs_to('User');
}
所以我坚持的是如何处理对象到 return experience, compensation
因为那些我需要在不止一个页面上的东西,起初我在我的控制器中做了这个
public function get_index($username = null)
{
$user = User::get_profile($username);
if (is_null($user)) return Response::error('404');
switch ($user->detail->experience) {
case 1:
$user->detail->experience = "No experience";
break;
case 2:
$user->detail->experience = "Some experience";
break;
case 3:
$user->detail->experience = "Experienced";
break;
case 4:
$user->detail->experience = "Very experienced";
break;
}
switch ($user->detail->compensation) {
case 1:
$user->detail->compensation = "Any";
break;
case 2:
$user->detail->compensation = "Depends on Assignment ";
break;
case 3:
$user->detail->compensation = "Paid Assignments Only ";
break;
case 4:
$user->detail->compensation = "Time for Print ";
break;
}
$this->layout->title = 'Profile' . ' ' . $username ;
$this->layout->content = View::make( 'user.profile' )->with( 'user', $user );
}
而且我知道这是我应该提出的麦芽汁想法,因为它不能解决我的问题,无效,我仍然需要复制。
那么有人可以向我展示处理这些问题的示例和有效方法吗?
将不胜感激,谢谢