<code style=
"box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"
><span style=
"box-sizing: border-box;"
><?php</span>
<span style=
"box-sizing: border-box;"
>
namespace
</span> <span style=
"box-sizing: border-box;"
>app</span>\<span style=
"box-sizing: border-box;"
>controllers</span>;
<span style=
"box-sizing: border-box;"
>
use
</span> <span style=
"box-sizing: border-box;"
>Yii</span>;
<span style=
"box-sizing: border-box;"
>
use
</span> <span style=
"box-sizing: border-box;"
>yii</span>\<span style=
"box-sizing: border-box;"
>base</span>\<span style=
"box-sizing: border-box;"
>Model</span>;
<span style=
"box-sizing: border-box;"
>
use
</span> <span style=
"box-sizing: border-box;"
>yii</span>\<span style=
"box-sizing: border-box;"
>web</span>\<span style=
"box-sizing: border-box;"
>Controller</span>;
<span style=
"box-sizing: border-box;"
>
use
</span> <span style=
"box-sizing: border-box;"
>app</span>\<span style=
"box-sizing: border-box;"
>models</span>\<span style=
"box-sizing: border-box;"
>Setting</span>;
<span style=
"box-sizing: border-box;"
><span style=
"box-sizing: border-box;"
>
class
</span> <span style=
"box-sizing: border-box;"
>SettingsController</span> <span style=
"box-sizing: border-box;"
>
extends
</span> <span style=
"box-sizing: border-box;"
>Controller</span></span>{
<span style=
"box-sizing: border-box;"
>
<span style=
"box-sizing: border-box;"
>
public
</span> <span style=
"box-sizing: border-box;"
><span style=
"box-sizing: border-box;"
>
function
</span> <span style=
"box-sizing: border-box;"
>actionUpdate</span><span style=
"box-sizing: border-box;"
>()</span>
</span>{
<span style=
"box-sizing: border-box;"
>
$settings
</span> = Setting::find()->indexBy(<span style=
"box-sizing: border-box;"
>
'id'
</span>)->all();
<span style=
"box-sizing: border-box;"
>
if
</span> (Model::loadMultiple(<span style=
"box-sizing: border-box;"
>
$settings
</span>, Yii::<span style=
"box-sizing: border-box;"
>
$app
</span>->request->post()) && Model::validateMultiple(<span style=
"box-sizing: border-box;"
>
$settings
</span>)) {
<span style=
"box-sizing: border-box;"
>
foreach
</span> (<span style=
"box-sizing: border-box;"
>
$settings
</span> <span style=
"box-sizing: border-box;"
>
as
</span> <span style=
"box-sizing: border-box;"
>
$setting
</span>) {
<span style=
"box-sizing: border-box;"
>
$setting
</span>->save(<span style=
"box-sizing: border-box;"
>false</span>);
}
<span style=
"box-sizing: border-box;"
>
return
</span> <span style=
"box-sizing: border-box;"
>
$this
</span>->redirect(<span style=
"box-sizing: border-box;"
>
'index'
</span>);
}
<span style=
"box-sizing: border-box;"
>
return
</span> <span style=
"box-sizing: border-box;"
>
$this
</span>->render(<span style=
"box-sizing: border-box;"
>
'update'
</span>, [<span style=
"box-sizing: border-box;"
>
'settings'
</span> => <span style=
"box-sizing: border-box;"
>
$settings
</span>]);
}
}
</code>