presenter 层的用法?
presenter的作用是把view层中复杂的逻辑代码抽象出来,在presenter层写出来,在模板中渲染
public function input_field()
{
if($this->wrappedObject->type === 'select')
{
$options = $this->wrappedObject->settingSelectOptions;
$str = "<select name=".$this->wrappedObject->name." class='form-control'>";
foreach($options as $key=>$value)
{
if($this->wrappedObject->value == $value['id'])
{
$str .= "<option selected value='".$value['id']."'>".$value['body']."</option>";
}
else
{
$str .= "<option value='".$value['id']."'>".$value['body']."</option>";
}
}
$str .= "</select>";
return $str;
}
if($this->wrappedObject->type === 'text')
{
$name = $this->wrappedObject->name;
$value = $this->wrappedObject->value;
$str = <<<str
<input class="form-control" name="$name" value="$value">
str;
return $str;
}
}
那么在blabe模板中很简单
{!! $setting->input_field !!}渲染就完事了,但是在php代码里用字符串写html标签,这又脱离了模板和逻辑分离的MVC架构模式,在php里写标签也特别容易出错
presenter层存在的意义到底是什么呢?
以后修改起来,只要修改一个地方