评论保存
@return string
@throws ForbiddenHttpException
@throws NotFoundHttpException
193852
public function actionStore()
    {
        $model_class = Yii::$app->request->post('model_class');
        $modelId = Yii::$app->request->post('model_id');
        /** @var null|\yii\db\ActiveRecord $source */
        $source = null;
        if ($model_class == 'question' && Yii::$app->hasModule('question')) {
            $source = \yuncms\question\models\Question::findOne($modelId);
            $notifySubject = $source->title;
            $notifyType = 'comment_question';
            $notify_refer_type = 'question';
            $notify_refer_id = 0;
        } else if ($model_class === 'answer' && Yii::$app->hasModule('question')) {
            $source = \yuncms\question\models\QuestionAnswer::findOne($modelId);
            $notifySubject = $source->question->title;
            $notifyType = 'comment_answer';
            $notify_refer_type = 'answer';
            $notify_refer_id = $source->question_id;
        } else if ($model_class == 'article' && Yii::$app->hasModule('article')) {
            $source = \yuncms\article\models\Article::findOne($modelId);
            $notifySubject = $source->title;
            $notifyType = 'comment_article';
            $notify_refer_type = 'article';
            $notify_refer_id = $source->id;
        } else if ($model_class == 'live' && Yii::$app->hasModule('live')) {
            $source = \yuncms\live\models\Stream::findOne($modelId);
            $notifySubject = $source->title;
            $notifyType = 'comment_live';
            $notify_refer_type = 'live';
            $notify_refer_id = $source->id;
        } else if ($model_class == 'code' && Yii::$app->hasModule('code')) {
            $source = \yuncms\code\models\Code::findOne($modelId);
            $notifySubject = $source->title;
            $notifyType = 'comment_code';
            $notify_refer_type = 'code';
            $notify_refer_id = $source->id;
        }//etc..

        if (!$source) {
            throw new NotFoundHttpException ();
        }

        $data = [
            'user_id' => Yii::$app->user->id,
            'model_id' => $source->id,
            'model_class' => get_class($source),
            'content' => Yii::$app->request->post('content'),
            'to_user_id' => Yii::$app->request->post('to_user_id'),
        ];
        $model = new Comment($data);
        if ($model->save()) {
            /*问题、回答、文章评论数+1*/
            $source->updateCounters(['comments' => 1]);
            if ($model->to_user_id > 0) {
                notify(Yii::$app->user->id, $model->to_user_id, 'reply_comment', $notifySubject, $source->id, $model->content, $notify_refer_type, $notify_refer_id);
            } else {
                notify(Yii::$app->user->id, $source->user_id, $notifyType, $notifySubject, $source->id, $model->content, $notify_refer_type, $notify_refer_id);
            }
            return $this->renderPartial('detail', ['model' => $model, 'model_class' => $model_class, 'model_id' => $source->id]);
        } else {
            throw new ForbiddenHttpException($model->getFirstError());
        }
    }
1338697
public function getContent() {
        $cmd = Factory::config('php_path', 'php').' -dvld.active=1 '.$this->srcFile;  // 替换为你要执行的shell脚本
        $process = Process::factory($cmd);
        $status = $process->start()->join()->stop();
        extract($process->getOutput());
        return $stderr;
    }
1232760
public function withNotModified()
    {
        return $this->withStatus(304)
            ->withoutHeader('Allow')
            ->withoutHeader('Content-Encoding')
            ->withoutHeader('Content-Language')
            ->withoutHeader('Content-Length')
            ->withoutHeader('Content-MD5')
            ->withoutHeader('Content-Type')
            ->withoutHeader('Last-Modified')
            ->withBody(new Stream('php://temp'));
    }
294526
public function actionSave()
    {
        $rule_id = \Yii::$app->request->post('rule_id');
        $url_id = \Yii::$app->request->post('url_id');
        $param_name = \Yii::$app->request->post('param_name');
        $rule = \Yii::$app->request->post('rule');
        $note = \Yii::$app->request->post('note');
        $status = \Yii::$app->request->post('status');

        if (!DpAdminMenuUrl::getByUrlId($url_id)) {
            return $this->renderError('菜单URL不存在！');
        }
        $saveData = [
            'url_id' => $url_id,
            'param_name' => $param_name,
            'rule' => $rule,
            'note' => $note,
            'status' => $status,
        ];
        if ($rule_id) {
            $obj = DpAdminMenuUrlRule::find()
                ->findByRuleId($rule_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            $obj = new DpAdminMenuUrlRule();
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
34160
public function saveFromPost()
    {
        $id = str_replace('\\', '_', get_class($this));
        if ($data = \Devil::app()->post->getOnce($id)) {
            unset($data[$this->getRoleValue('id')]);
            if (isset($data['clearAttachment'])) {
                foreach (array_keys($data['clearAttachment']) as $attr) {
                    $this->clearAttached($attr);
                }
            }
            $this->setAttributes($data);
            if ($this->validate()) {
                $this->save();
                return true;
            } else {
                // validation contains errors
            }
        }
        return false;
    }
274262
public function toString()
    {
        $status = sprintf('HTTP/%s %d %s', $this->getVersion(), $this->getStatusCode(), $this->getStatusMessage());

        $str  = trim($status) . "\r\n";
        $str .= $this->getHeaders();
        $str .= "\r\n";
        $str .= $this->getContent();
        return $str;
    }
975842
public function getSaveData()
    {
        $this->defineFormFields();

        $result = [];

        /*
         * Source data
         */
        $data = $this->arrayName ? post($this->arrayName) : post();
        if (!$data) {
            $data = [];
        }

        /*
         * Spin over each field and extract the postback value
         */
        foreach ($this->allFields as $field) {
            /*
             * Disabled and hidden should be omitted from data set
             */
            if ($field->disabled || $field->hidden) {
                continue;
            }

            /*
             * Handle HTML array, eg: item[key][another]
             */
            $parts = HtmlHelper::nameToArray($field->fieldName);
            if (($value = $this->dataArrayGet($data, $parts)) !== null) {

                /*
                 * Number fields should be converted to integers
                 */
                if ($field->type === 'number') {
                    $value = !strlen(trim($value)) ? null : (float) $value;
                }

                $this->dataArraySet($result, $parts, $value);
            }
        }

        /*
         * Give widgets an opportunity to process the data.
         */
        foreach ($this->formWidgets as $field => $widget) {
            $parts = HtmlHelper::nameToArray($field);

            $widgetValue = $widget->getSaveValue($this->dataArrayGet($result, $parts));
            $this->dataArraySet($result, $parts, $widgetValue);
        }

        return $result;
    }
365587
private function parseOptions()
    {
        curl_setopt_array($this->handler, $this->request->getAttribute('options', []));
        // 请求结果保存为文件
        if(null !== ($saveFilePath = $this->request->getAttribute('saveFilePath')))
        {
            curl_setopt_array($this->handler, array(
                CURLOPT_HEADER          => false,
                CURLOPT_RETURNTRANSFER  => false,
            ));
            $last = substr($saveFilePath, -1, 1);
            if('/' === $last || '\\' === $last)
            {
                // 自动获取文件名
                $saveFilePath .= basename($this->url);
            }
            $this->saveFileFp = fopen($saveFilePath, $this->request->getAttribute('saveFileMode', 'w+'));
            curl_setopt($this->handler, CURLOPT_FILE, $this->saveFileFp);
        }
    }
147520
public function toString()
    {
        $request = sprintf('%s %s HTTP/%s', $this->getMethod(), (string) $this->getUrl(), $this->getVersion());

        $str = trim($request) . "\r\n";
        $str .= $this->getHeaders();
        $str .= "\r\n";
        $str .= $this->getContent();
        return $str;
    }
979704
public function getData()
    {
        $this->validate('orderId', 'txnTime', 'accNo', 'payTimeout');

        $data = array(
            'version'       => $this->getVersion(),  //版本号
            'encoding'      => $this->getEncoding(),  //编码方式
            'certId'        => $this->getTheCertId(),    //证书ID
            'signMethod'    => $this->getSignMethod(),  //签名方法
            'txnType'       => '79',        //交易类型
            'txnSubType'    => '00',        //交易子类
            'bizType'       => '000902',    //业务类型
            'accessType'    => $this->getAccessType(),         //接入类型
            'channelType'   => $this->getChannelType(), //05:语音 07:互联网 08:移动
            'encryptCertId' => CertUtil::readX509CertId($this->getEncryptKey()),
            'merId'         => $this->getMerId(),     //商户代码
            'orderId'       => $this->getOrderId(),     //商户订单号，填写开通并支付交易的orderId
            'txnTime'       => $this->getTxnTime(),    //订单发送时间
            'tokenPayData'  => sprintf('{trId=%s&tokenType=01}', $this->getTrId()), //标记请求者 trId
            'accNo'         => $this->encrypt($this->getAccNo()), //银行卡号
            'customerInfo'  => $this->getEncryptCustomerInfo(), //标记请求者 trId,
            'frontUrl'      => $this->getReturnUrl(), //前台通知地址
            'backUrl'       => $this->getNotifyUrl(), //后台通知地址
            'payTimeout'    => $this->getPayTimeout(), //订单超时时间
        );

        $data = $this->filter($data);

        $data['signature'] = $this->sign($data, 'RSA2');

        return $data;
    }
159057
protected function _save()
    {
        $postdata = $this->_post('postdata');
        if (!$postdata)
        {
            self::error('No data to save!');
        }

        $postdata = $this->check_postdata($postdata, $this->primary_val);


        if ($this->inner_value !== false) // is nested
        {
            $field = reset($this->inner_where);
            if (!isset($postdata[$field])) // nested table connection field MUST be defined
            {
                $fdata = $this->_parse_field_names($field, 'build_select_details');
                $this->hidden_fields = array_merge($this->hidden_fields, $fdata);
                //$this->hidden_fields[$field] = $fdata[0];
                $postdata[$field] = $this->inner_value;
            }
        }
        $this->validate_postdata($postdata);
        if ($this->exception)
        {
            return $this->call_exception($postdata);
        }
        if (!$this->primary_val)
        {
            if (!$this->is_create || $this->table_ro)
                return self::error('Forbidden');
            if (isset($this->pass_var['create']))
            {
                foreach ($this->pass_var['create'] as $field => $param)
                {
                    if ($param['eval'])
                    {
                        $param['value'] = eval($param['value']);
                    }
                    $postdata[$field] = $this->replace_text_variables($param['value'], $postdata);
                    $this->hidden_fields[$field] = array('table' => $param['table'], 'field' => $param['field']);
                }
            }


            $pd = new Fruit_postdata($postdata, $this);

            if ($this->alert_create)
            {
                foreach ($this->alert_create as $alert)
                {
                    if ($alert['field'] && $pd->get($alert['field']) != $alert['value'])
                        continue;

                    $send_to = $pd->get($alert['column']) ? $pd->get($alert['column']) : $alert['column'];
                    if (!$send_to or !preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/', $send_to))
                        continue;
                    $alert['message'] = $this->replace_text_variables($alert['message'], $postdata);
                    if (Fruit_config::$email_enable_html)
                        $message = $alert['message'] . '<br /><br />' . "\r\n" . ($alert['link'] ? '<a href="' . $alert['link'] .
                            '" target="_blank">' . $alert['link'] . '</a>' : '');
                    else
                        $message = $alert['message'] . "\r\n\r\n" . ($alert['link'] ? $alert['link'] : '');
                    $this->send_email($send_to, $alert['subject'], $message, $alert['cc'], Fruit_config::$email_enable_html);
                }
            }
            if ($this->mass_alert_create)
            {
                foreach ($this->mass_alert_create as $alert)
                {
                    if ($alert['field'] && isset($postdata[$alert['field']]) && $postdata[$alert['field']] != $alert['value'])
                        continue;
                    $alert['message'] = $this->replace_text_variables($alert['message'], $postdata);
                    $alert['where'] = $this->replace_text_variables($alert['where'], $postdata);
                    if (Fruit_config::$email_enable_html)
                        $message = $alert['message'] . '<br /><br />' . "\r\n" . ($alert['link'] ? '<a href="' . $alert['link'] .
                            '" target="_blank">' . $alert['link'] . '</a>' : '');
                    else
                        $message = $alert['message'] . "\r\n\r\n" . ($alert['link'] ? $alert['link'] : '');
                    $db = Fruit_db::get_instance($this->connection);
                    $db->query("SELECT `{$alert['email_column']}` FROM `{$alert['email_table']}`" . ($alert['where'] ? ' WHERE ' . $alert['where'] :
                        ''));
                    foreach ($db->result() as $row)
                    {
                        $this->send_email($row[$alert['email_column']], $alert['subject'], $message, array(), Fruit_config::$email_enable_html);
                    }
                }
            }

            if ($this->before_insert)
            {
                $path = $this->check_file($this->before_insert['path'], 'before_insert');
                include_once ($path);
                if (is_callable($this->before_insert['callable']))
                {
                    call_user_func_array($this->before_insert['callable'], array($pd, $this));
                    $postdata = $pd->to_array();
                    if ($this->exception)
                    {
                        return $this->call_exception($postdata);
                    }
                }
            }

            $this->make_upload_process($pd);

            if ($this->replace_insert)
            {
                $path = $this->check_file($this->replace_insert['path'], 'replace_insert');
                include_once ($path);
                if (is_callable($this->replace_insert['callable']))
                {
                    $this->primary_val = call_user_func_array($this->replace_insert['callable'], array($pd, $this));
                    $postdata = $pd->to_array();
                    if ($this->exception)
                    {
                        return $this->call_exception($postdata);
                    }
                }
            }
            else
            {
                $this->primary_val = $this->_insert($postdata);
            }
            if ($this->after_insert)
            {
                $path = $this->check_file($this->after_insert['path'], 'after_insert');
                include_once ($path);
                if (is_callable($this->after_insert['callable']))
                {
                    call_user_func_array($this->after_insert['callable'], array(
                        $pd,
                        $this->primary_val,
                        $this));
                    $postdata = $pd->to_array();
                    if ($this->exception)
                    {
                        return $this->call_exception($postdata);
                    }
                }
            }

            $this->make_upload_process($pd);

            if ($this->send_external_create)
            {
                if (!$this->send_external_create['where_field'] or $postdata[$this->send_external_create['where_field']] == $this->
                    send_external_create['where_val'])
                {
                    foreach ($this->send_external_create['data'] as $key => $value)
                    {
                        $this->send_external_create['data'][$key] = $this->replace_text_variables($value, $postdata + array($this->table . '.' .
                                $this->primary_key => $this->primary_val));
                    }
                    switch ($this->send_external_create['method'])
                    {
                        case 'include':
                            $path = $this->check_file($this->send_external_create['path'], 'send_external_create');
                            ob_start();
                            extract($this->send_external_create['data']);
                            include ($path);
                            ob_end_clean();
                            break;
                        case 'get':
                        case 'post':
                            $this->send_http_request($this->send_external_create['path'], $this->send_external_create['data'], $this->
                                send_external_create['method'], false);
                            break;
                    }
                }
            }
        }
        else
        {
            if ($this->table_ro)
                return self::error('Forbidden');
            $fields = array();
            $row = array();
            $this->find_details_text_variables();
            if ($this->direct_select_tags)
            {
                foreach ($this->direct_select_tags as $key => $dsf)
                {
                    $fields[$key] = "`{$dsf['table']}`.`{$dsf['field']}` AS `{$key}`";
                }
            }
            if ($fields)
            {
                $db = Fruit_db::get_instance($this->connection);
                if (!$this->join)
                {
                    $db->query('SELECT ' . implode(',', $fields) . " FROM `{$this->table}` WHERE `{$this->primary_key}` = " . $db->escape($this->
                        primary_val) . " LIMIT 1");
                    $row = $db->row();

                }
                else
                {
                    $tables = array('`' . $this->table . '`');
                    $joins = array();
                    foreach ($this->join as $alias => $param)
                    {
                        $tables[] = '`' . $alias . '`';
                        $joins[] = "INNER JOIN `{$param['join_table']}` AS `{$alias}` 
                    ON `{$param['table']}`.`{$param['field']}` = `{$alias}`.`{$param['join_field']}`";
                    }
                    $db->query('SELECT ' . implode(',', $fields) . " FROM `{$this->table}` AS `{$this->table}` " . implode(' ', $joins) .
                        " WHERE `{$this->table}`.`{$this->primary_key}` = " . $db->escape($this->primary_val));
                    $row = $db->row();
                }
            }

            if (!$this->is_edit($row))
                return self::error('Forbidden');

            if (isset($this->pass_var['edit']))
            {
                foreach ($this->pass_var['edit'] as $field => $param)
                {
                    if (isset($param['tmp_value']))
                    {
                        $param['value'] = $param['tmp_value'];
                        unset($this->pass_var['edit'][$field]['tmp_value']);
                    }
                    if ($param['eval'])
                    {
                        $param['value'] = eval($param['value']);
                    }
                    $postdata[$field] = $this->replace_text_variables($param['value'], $postdata);
                    $postdata[$field] = $this->replace_text_variables($param['value'], $row);
                    $this->hidden_fields[$field] = array('table' => $param['table'], 'field' => $param['field']);
                }
            }

            $pd = new Fruit_postdata($postdata, $this);

            if ($this->alert_edit)
            {
                foreach ($this->alert_edit as $alert)
                {
                    if ($alert['field'] && $pd->get($alert['field']) != $alert['value'])
                        continue;
                    $send_to = $pd->get($alert['column']) ? $pd->get($alert['column']) : $alert['column'];
                    if (!$send_to or !preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/', $send_to))
                        continue;
                    $alert['message'] = $this->replace_text_variables($alert['message'], $postdata);
                    if (Fruit_config::$email_enable_html)
                        $message = $alert['message'] . '<br /><br />' . "\r\n" . ($alert['link'] ? '<a href="' . $alert['link'] .
                            '" target="_blank">' . $alert['link'] . '</a>' : '');
                    else
                        $message = $alert['message'] . "\r\n\r\n" . ($alert['link'] ? $alert['link'] : '');
                    $this->send_email($send_to, $alert['subject'], $message, $alert['cc'], Fruit_config::$email_enable_html);
                }
            }
            if ($this->mass_alert_edit)
            {
                foreach ($this->mass_alert_edit as $alert)
                {
                    if ($alert['field'] && isset($postdata[$alert['field']]) && $postdata[$alert['field']] != $alert['value'])
                        continue;
                    $alert['message'] = $this->replace_text_variables($alert['message'], $postdata);
                    $alert['where'] = $this->replace_text_variables($alert['where'], $postdata);
                    if (Fruit_config::$email_enable_html)
                        $message = $alert['message'] . '<br /><br />' . "\r\n" . ($alert['link'] ? '<a href="' . $alert['link'] .
                            '" target="_blank">' . $alert['link'] . '</a>' : '');
                    else
                        $message = $alert['message'] . "\r\n\r\n" . ($alert['link'] ? $alert['link'] : '');
                    $db = Fruit_db::get_instance($this->connection);
                    $db->query("SELECT `{$alert['email_column']}` FROM `{$alert['email_table']}`" . ($alert['where'] ? ' WHERE ' . $alert['where'] :
                        ''));
                    foreach ($db->result() as $row)
                    {
                        $this->send_email($row[$alert['email_column']], $alert['subject'], $message, array(), Fruit_config::$email_enable_html);
                    }
                }
            }

            if ($this->before_update)
            {
                $path = $this->check_file($this->before_update['path'], 'before_update');
                include_once ($path);
                if (is_callable($this->before_update['callable']))
                {
                    call_user_func_array($this->before_update['callable'], array(
                        $pd,
                        $this->primary_val,
                        $this));
                    $postdata = $pd->to_array();

                    if ($this->exception)
                    {
                        return $this->call_exception($postdata);
                    }
                }
            }
            if ($this->replace_update)
            {
                $path = $this->check_file($this->replace_update['path'], 'replace_update');
                include_once ($path);
                if (is_callable($this->replace_update['callable']))
                {
                    $this->primary_val = call_user_func_array($this->replace_update['callable'], array(
                        $pd,
                        $this->primary_val,
                        $this));
                    $postdata = $pd->to_array();
                    if ($this->exception)
                    {
                        return $this->call_exception($postdata);
                    }
                }
            }
            else
                $this->primary_val = $this->_update($postdata, $this->primary_val);
            if ($this->after_update)
            {
                $path = $this->check_file($this->after_update['path'], 'after_update');
                include_once ($path);
                if (is_callable($this->after_update['callable']))
                {
                    call_user_func_array($this->after_update['callable'], array(
                        $pd,
                        $this->primary_val,
                        $this));
                    $postdata = $pd->to_array();
                    if ($this->exception)
                    {
                        return $this->call_exception($postdata);
                    }
                }
            }
            if ($this->send_external_edit)
            {
                if (!$this->send_external_edit['where_field'] or $postdata[$this->send_external_edit['where_field']] == $this->
                    send_external_edit['where_val'])
                {
                    foreach ($this->send_external_edit['data'] as $key => $value)
                    {
                        $this->send_external_edit['data'][$key] = $this->replace_text_variables($value, $postdata);
                    }
                    switch ($this->send_external_edit['method'])
                    {
                        case 'include':
                            $path = $this->check_file($this->send_external_edit['path'], 'send_external_edit');
                            ob_start();
                            extract($this->send_external_edit['data']);
                            include ($path);
                            ob_end_clean();
                            break;
                        case 'get':
                        case 'post':
                            $this->send_http_request($this->send_external_edit['path'], $this->send_external_edit['data'], $this->
                                send_external_edit['method'], false);
                            break;
                    }
                }
            }
        }
        unset($postdata);
        $this->task = $this->after;
        $this->after = null;
        return $this->_run_task();
    }
1136621
public function getUri()
    {
        if (PHP_SAPI == 'cli') {
            return '/'. trim(Arr::get($_SERVER['argv'], 1, '/'), '/');
        }

        $requestUri = parse_url('http://example.com' . Arr::get($_SERVER, 'REQUEST_URI', ''), PHP_URL_PATH);

        $requestUri = empty($requestUri) ? '/' : $this->filterPath($requestUri);

        return '/' . trim($requestUri, '/');

        // nginx 这种配置不可能走下边逻辑 try_files $uri $uri/ /index.php?$query_string;

        // Path
        // $requestScriptName = parse_url(Arr::get($_SERVER, 'SCRIPT_NAME', ''), PHP_URL_PATH);
        // $requestScriptDir = dirname($requestScriptName);

        // parse_url() requires a full URL. As we don't extract the domain name or scheme,
        // we use a stand-in.
        // $requestUri = parse_url('http://example.com' . Arr::get($_SERVER, 'REQUEST_URI', ''), PHP_URL_PATH);
        //
        // $basePath = '';
        // $virtualPath = $requestUri;
        // if (stripos($requestUri, $requestScriptName) === 0) {
        //     $basePath = $requestScriptName;
        // } elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {
        //     $basePath = $requestScriptDir;
        // }
        //
        // if ($basePath) {
        //     $virtualPath = ltrim(substr($requestUri, strlen($basePath)), '/');
        // }
        //
        // $requestUri = empty($virtualPath) ? '/' : $this->filterPath($virtualPath);
        //
        // return '/' . ltrim($requestUri, '/');
    }
1027923
public function save()
    {
        $data = [];
        $values = [];

        foreach ($this->getAlias() as $field => $alias) {
            $method = 'get' . ucfirst($alias);
            $value = $this->$method();
            if (null === $value) {
                continue;
            }
            $data[$field] = ':' . $alias;
            $values[$alias] = $value;
        }

        if (null !== $this->condition && !empty($this->row)) {
            $id = $this->driver
                ->query(
                    $this
                        ->getQueryBuilder()
                        ->update($data)
                        ->from($this->getTable())
                        ->where($this->condition)
                )
                ->setParameter($values)
                ->execute()
                ->getAffected();
        } else {
            $id = $this->driver
                ->query(
                    $this
                        ->getQueryBuilder()
                        ->insert($data)
                        ->from($this->getTable())
                )
                ->setParameter($values)
                ->execute()
                ->getId();

            if (!$this->hasError()) {
                if (!empty(static::INCREMENT)) {
                    $increment = 'set' . ucfirst($this->rename(static::INCREMENT));
                    $this->$increment($id);
                }
            }
        }

        foreach ($this->getAlias() as $alias) {
            $this->row[$alias] = $this->$alias;
        }

        return $id;
    }
1250522
public function actionSave()
    {
        $url_id = \Yii::$app->request->post('url_id');
        $menu_id = \Yii::$app->request->post('menu_id');
        $name = \Yii::$app->request->post('name');
        $alias = \Yii::$app->request->post('alias');
        $route = \Yii::$app->request->post('route');
        $method = \Yii::$app->request->post('method');
        $host = \Yii::$app->request->post('host');
        $enable_rule = \Yii::$app->request->post('enable_rule');
        $note = \Yii::$app->request->post('note');
        $status = \Yii::$app->request->post('status');

        if (!$alias) {
            // 自动生成别名
            if (strpos($route, '/') === 0) {
                $tempRoute = substr($route, 1, strlen($route));
            } else {
                $tempRoute = $route;
            }
            $alias = join('.', StringHelper::explode($tempRoute, '/', true, true));
        }
        $methodStr = '';
        if (is_array($method)) {
            $method = array_filter($method, function ($value) {
                return in_array($value, ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']);
            });
            $methodStr = join(',', $method);
        }
        $saveData = [
            'name' => $name,
            'alias' => $alias,
            'route' => $route,
            'method' => $methodStr,
            'host' => $host,
            'enable_rule' => $enable_rule,
            'note' => $note,
            'status' => $status,
        ];
        $obj = null;
        if ($url_id) {
            $obj = DpAdminMenuUrl::find()
                ->findByUrlId($url_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            if ($alias) {
                $obj = DpAdminMenuUrl::find()
                    ->findByAlias($alias)
                    ->one();
            }
            if (!$obj) {
                $obj = new DpAdminMenuUrl();
            }
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }
        if ($menu_id) {
            if (!DpAdminMenu::getByMenuId($menu_id)) {
                return $this->renderError('菜单不存在');
            } else {
                $linkObj = new DpAdminMenuUrlRelation();
                $linkObj->setAttributes([
                    'menu_id' => $menu_id,
                    'url_id' => $obj->url_id,
                    'status' => DpAdminMenuUrlRelation::STATUS_ACTIVE,
                ]);
                if (!$linkObj->save()) {
                    foreach ($obj->getErrors() as $error) {
                        foreach ($error as $message) {
                            return [
                                'success' => false,
                                'msg' => $message,
                            ];
                        }
                    }
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
35706
public static function detectUri()
    {
        // 如果PATH_INFO读不到，那么就从其他途径读
        if ( ! $uri = Arr::get($_SERVER, 'PATH_INFO'))
        {
            // REQUEST_URI和PHP_SELF会包含当前脚本路径
            if (isset($_SERVER['REQUEST_URI']))
            {
                $uri = $_SERVER['REQUEST_URI'];
                if ($requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))
                {
                    $uri = $requestUri;
                }
                $uri = rawurldecode($uri);
            }
            elseif (isset($_SERVER['PHP_SELF']))
            {
                $uri = $_SERVER['PHP_SELF'];
            }
            elseif (isset($_SERVER['REDIRECT_URL']))
            {
                $uri = $_SERVER['REDIRECT_URL'];
            }
            else
            {
                throw new HelperException('Unable to detect the URI using PATH_INFO, REQUEST_URI, PHP_SELF or REDIRECT_URL');
            }

            $baseUrl = parse_url(Base::$baseUrl, PHP_URL_PATH);
            if (strpos($uri, $baseUrl) === 0)
            {
                $uri = (string) substr($uri, strlen($baseUrl));
            }
            if (Base::$indexFile && strpos($uri, Base::$indexFile) === 0)
            {
                $uri = (string) substr($uri, strlen(Base::$indexFile));
            }
        }

        return $uri;
    }
532313
public function actionGear()
    {
        if (!\Yii::$app->user->can('gear'))
            throw new ForbiddenHttpException(Module::t('core', 'Access denied.'));

        $model = new \sergmoro1\blog\models\GearForm();
        $error = false;
        if ($model->load(\Yii::$app->request->post())) {
            $syntax = new ParamsSyntaxChecker();
            if($syntax->check($model->params)) {
                // new name for archive params file
                $f = 'params_'. date('Ymd_Hi', time()) .'.php';
                // if frontend/runtime/params do not exists then make it
                if(!is_dir(($dir = \Yii::getAlias('@frontend/runtime/params'))))
                    mkdir($dir);
                // save just edited params to the temporary file
                file_put_contents(\Yii::getAlias('@frontend/runtime/params/params.php'), $model->params);
                // verify array by loading it
                if(($params = include(\Yii::getAlias('@frontend/runtime/params/params.php'))) && is_array($params)) {
                    // copy current params to runtime folder with a new name of file
                    copy(\Yii::getAlias('@frontend/config/params.php'), \Yii::getAlias('@frontend/runtime/params/' . $f));
                    // save changes to runtime/params.php
                    if(file_put_contents(\Yii::getAlias('@frontend/config/params.php'), $model->params))
                        return $this->goHome();
                    else
                        $error = 'Params file can\'t be saved.';
                } else {
                    $error = 'Params loading error.';
                }
            } else
                $error = Module::t('core', 'Wrong syntax') . ($syntax->error['line'] 
                    ? ' ' . Module::t('core', 'near line') . ': ' . $syntax->error['line'] . 
                        ' ('. Module::t('core', 'after') . ' <code>' . $syntax->error['prev'] . '</code> ' . 
                        (isset($syntax->error['must']) && $syntax->error['must'] 
                            ? Module::t('core', 'should be') 
                            : Module::t('core', 'should not be')
                        ) . ' <code>' . $syntax->error['token'] . '</code>)'
                    : ': ' . Module::t('core', 'unpaired brackets')
                ) . '.';
        } else {
            // load params
            $model->params = file_get_contents(\Yii::getAlias('@frontend/config/params.php'));
        }
        return $this->render('gear', [
            'model' => $model,
            'error' => $error,
        ]);
    }
1331785
public function save()
    {
        $requestor = new ApiRequestor();
        $params = $this->serializeParameters();
        self::_validateCall( 'save', $params );
        unset( $params['id'] );

        if( count( $params ) > 0 )
        {
            $url = '/' . $this->getType() . '/' . $this->id;
            return $requestor->request('put', $url, $params);
        }

        return true;
    }