本文整理汇总了PHP中ConfigFile::model方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigFile::model方法的具体用法?PHP ConfigFile::model怎么用?PHP ConfigFile::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigFile
的用法示例。
在下文中一共展示了ConfigFile::model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
public function loadModel($id)
{
$model = ConfigFile::model()->findByPk((int) $id);
if ($model === null) {
throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.'));
}
return $model;
}
示例2: actionEditConfig
public function actionEditConfig($id, $config, $ro, $file, $dir)
{
Yii::app()->user->can($id, 'edit configs', true);
$cfg = ConfigFile::model()->findByPk($config);
if (!$cfg || !preg_match('/' . $cfg->file . '/', $file)) {
throw new CHttpException(404, Yii::t('mc', 'Config file not found'));
}
$rules = CJSON::decode($cfg->options);
$ro = $ro == Yii::t('mc', 'True') ? true : false;
$error = false;
$name = $this->replData($cfg->name, $file, $dir);
if (!$ro && @$_POST['save'] === 'true') {
$data = '';
if ($cfg->type == 'properties') {
$acceptAll = @$rules['*']['visible'] ? true : false;
if (@count($_POST['option'])) {
foreach ($_POST['option'] as $opt => $val) {
if ($acceptAll || !isset($rules[$opt]['visible']) || $rules[$opt]['visible']) {
$data .= $opt . '=' . $val . "\n";
}
}
}
} else {
$data = $_POST['list'];
}
$data = $data ? str_replace(array('\\', ' ;'), array('\\\\', ' \\;'), $data) : '';
$data = preg_replace('/\\n\\r?/', ' ;', $data);
$d = null;
if (!McBridge::get()->serverCmd($id, 'cfgfile set' . $cfg->type . ':' . $file . ':' . $dir . ':' . $data, $d)) {
$error = McBridge::get()->lastError();
} else {
if (@$d[0]['accepted'] != 'True') {
$error = isset($d[0]['message']) ? $d[0]['message'] : Yii::t('mc', 'Error updating config file!');
} else {
Yii::app()->user->setFlash('server', Yii::t('mc', 'Config File saved.'));
$this->redirect(array('configs', 'id' => $id));
}
}
}
$data = null;
if (!McBridge::get()->serverCmd($id, 'cfgfile get' . $cfg->type . ':' . $file . ':' . $dir . ':', $data)) {
$error = McBridge::get()->lastError();
}
$opts = array();
$list = '';
if ($data && $cfg->type == 'properties') {
if (@is_array($rules)) {
foreach ($rules as $match => $info) {
if (isset($info['select']) && $info['select'] === 'bool') {
$info['select'] = array('true' => Yii::t('mc', 'Enabled'), 'false' => Yii::t('mc', 'Disabled'));
}
$found = false;
foreach ($data as $k => $v) {
$opt = array();
$opt['name'] = $v['option'];
$opt['value'] = $v['value'];
$opt['visible'] = true;
if (strlen($opt['name']) && $match != '*' && $match != $opt['name']) {
continue;
}
$found = true;
if (isset($info['visible'])) {
$opt['visible'] = $info['visible'];
}
if (isset($info['name'])) {
$opt['name'] = $info['name'];
}
if (isset($info['select'])) {
$opt['select'] = $info['select'];
}
if (isset($info['default']) && !strlen($opt['value'])) {
$opt['value'] = $info['default'];
}
if ($opt['visible']) {
$opts[$v['option']] = $opt;
}
if ($match != '*') {
unset($data[$k]);
break;
}
}
if (!$found && $match != '*' && !@$info['nocreate'] && (!isset($info['visible']) || $info['visible'])) {
$opts[$match] = $info;
if (!@$opts[$match]['name']) {
$opts[$match]['name'] = $match;
}
$opts[$match]['value'] = @$info['default'];
}
}
}
} else {
if ($data) {
foreach ($data as $line) {
if (isset($line['line'])) {
$list .= $line['line'] . "\n";
}
}
}
}
$this->render('editConfig', array('dataProvider' => new CArrayDataProvider($data, array('sort' => array('attributes' => array('name')), 'pagination' => array('pageSize' => 10))), 'type' => $cfg->type, 'list' => $list, 'options' => $opts, 'name' => $name, 'model' => $this->loadModel($id), 'error' => $error, 'ro' => $ro));
//.........这里部分代码省略.........