在视图中使用PHP更新单个字段 - 未定义变量

时间:2014-05-06 09:49:49

标签: variables cakephp controller undefined input-field

我搜索了很长时间,但我找不到解决问题的方法。 情况是,我在视图中集成了几个按钮并单击它们会影响更新单个输入字段。问题是我有警告,变量在视图中是未定义的。我理解为什么以及如何压制它们,但我不确定,如果这是一个很好的解决方案。有没有更好的方法来解决这个问题?什么是最佳做法?

以下是我在视图文件中的代码:

<?php 
echo $this->Form->create('Excel', array('type' => 'file'));
echo $this->Form->file('File');
echo $this->Form->submit('Upload xls File');
echo $this->Form->end();

echo $this->Form->create('Config');
//echo $this->Form->input('Name');
echo $this->Form->input('vlanNumber');
echo $this->Form->input('description', array('value' => $description));

echo $this->Form->input('preSharedKey', array('value' => $preSharedKey));
echo $this->Form->button('generate', array('name'=>'generateButton'));

echo $this->Form->input('customerPeerIp', array('default' => 'id_of_default_val','value' => $cusPeerIp));

“生成”按钮会影响新的preSharedKey。并且csv的上传影响了其他字段的更新。 控制器的相关代码是:

    public function inputData() {


    if ($this->request->is('post')) {
        $post_data = $this->request->data;
        if (isset($this->request->data['show'])) {  //Submit Button was clicked
            $this->Session->write('Configuration',$post_data); //Store the input fields in the session
            return $this->redirect(array('action' => 'showPreview'));
        } else if (isset($this->request->data['cancel'])) { // Cancel button was clicked: Go back to index site 
            return $this->redirect(array('action' => 'index')); 
        } else if (isset($this->request->data['generateButton'])) {
            return $this->set('preSharedKey', $this->getRandomString(20)); //Set a Pre Shared Key with 30 signs
        }
        if (!empty($this->data) && is_uploaded_file($this->data['Excel']['File']['tmp_name'])) {
            $this->importData($this->data['Excel']['File']['tmp_name']);
            $excel=new Excel();
            $values=$excel->getParams($this->data['Excel']['File']['tmp_name']);
            $this->set('description',$values['description']);
            $this->set('cusPeerIp',$values['cust_peer']);
            return;
              //this calls the Excel Class function

        }
        //print_r($post_data);
        //echo $post_data['Config']['Name'];
        //echo $this->request['Config']['task_1'];
    }
    $this->set('description','');
    $this->set('cusPeerIp','');
    $this->set('preSharedKey', '');
}

你能帮帮我吗?

0 个答案:

没有答案