将值存储到变量Opencart

时间:2016-02-02 08:34:07

标签: php variables opencart store

我认为这是打开购物车的基本问题,但是我无法修复它,因为我放了1个字段head_text_field然后我把变量放入控制器然后使用var_dump作为检查值

这对于View:

<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>

  <?php if ($error_warning) { ?>
    <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>

  <?php if ($success) { ?>
    <div class="success"><?php echo $success; ?></div>
  <?php } ?>

    <div class="box">
        <div class="heading">
            <h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
            <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
        </div>

        <div class="content">
          <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
            <table class="form">
                <tr>
                    <td><span class="required">*</span> <?php echo $entry_head; ?></td>
                    <td><input type="text" name="head_text_field" value="<?php echo $head_text_field; ?>" placeholder="Input Head Text" size="40"/></td>
                </tr>
            </table>
          </form>
        </div>
    </div>
</div>
<?php echo $footer; ?>

控制器:

<?php 
class ControllerItemItem extends Controller {
private $error = array(); 

public function index() {
    $this->language->load('item/item');
    $this->document->setTitle($this->language->get('heading_title')); 
    $this->getList();
}

protected function getList(){
    if (isset($this->request->get['head_text_field'])){
        $head_text_field = $this->request->get['head_text_field'];
        var_dump($head_text_field); exit; // VAR_DUMP HERE
    } else {
        $head_text_field = null;
        echo "FAILED";                // FAILED HERE
    }

    $this->data['breadcrumbs'] = array();
    $this->data['breadcrumbs'][] = array(
        'text'      => $this->language->get('text_home'),
        'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => false
    );

    $this->data['breadcrumbs'][] = array(
        'text'      => $this->language->get('heading_title'),
        'href'      => $this->url->link('module/item', 'token=' . $this->session->data['token'], 'SSL'),
        'separator' => ' :: '
    );

    $this->data['heading_title'] = $this->language->get('heading_title');
    $this->data['entry_head'] = $this->language->get('entry_head');
    $this->data['button_save'] = $this->language->get('button_save');
    $this->data['button_cancel'] = $this->language->get('button_cancel');


    $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
    $this->data['action'] = $this->url->link('item/item/insert', 'token=' . $this->session->data['token'], 'SSL');
    $this->data['token'] = $this->session->data['token'];

    $this->template = 'item/item.tpl';
    $this->children = array(
        'common/header',
        'common/footer'
    );      
    $this->response->setOutput($this->render());            
}

    public function insert()
{
    var_dump($head_text_field); exit;
}
}
?>

当我尝试输入时,结果是FAILED ??我错在哪里?对于模型我现在不在控制器中调用或使用它。

编辑1 对不起,我添加了功能插入,使其不是错误(对于控制器底部的按钮插入)

2 个答案:

答案 0 :(得分:0)

$这 - &GT;请求 - &GT;交[&#39; head_text_field&#39;]

答案 1 :(得分:0)

如果您想在视图中从variable获取opencart controller,则需要传递此变量,如下所示:

控制器文件

if (isset($this->request->post['head_text_field'])){
        $this->data['head_text_field'] = $this->request->get['head_text_field']; // Your variable
        var_dump($this->data['head_text_field']); exit; // VAR_DUMP HERE
    } else {
        $this->data['head_text_field'] = null;
        echo "FAILED";                // FAILED HERE
    }

现在,您可以在视图文件中将head_text_field设为$head_text_field

修改

public function insert()
{
    if (($this->request->server['REQUEST_METHOD'] == 'POST')) {
        echo $this->request->post['head_text_field']; // Your field value
    }
}