Hi, can someone help me with this problem on opencart? Warning: Illegal string offset 'meta_title' in

67 views Asked by At

The error

Warning: Illegal string offset 'meta_title' in C:\xampp\htdocs\test.pixel.com.ro\admin\controller\post\category.php on line 448Notice: Uninitialized string offset: 0 in C:\xampp\htdocs\test.pixel.com.ro\admin\controller\post\category.php on line 448Warning: Illegal string offset 'meta_title' in C:\xampp\htdocs\test.pixel.com.ro\admin\controller\post\category.php on line 448Warning: Illegal string offset 'meta_title' in C:\xampp\htdocs\test.pixel.com.ro\admin\controller\post\category.php on line 448Notice: Uninitialized string offset: 0 in C:\xampp\htdocs\test.pixel.com.ro\admin\controller\post\category.php on line 448Warning: Illegal string offset 'meta_title' in C:\xampp\htdocs\test.pixel.com.ro\admin\controller\post\category.php on line 448

controller\post\category.php

    if (isset($this->request->post['category_description'])) {
        $data['category_description'] = $this->request->post['category_description'];
    } elseif (!empty($category_info)) {
        $data['category_description'] = $this->model_post_category->getCategoryDescriptions($this->request->get['category_id']);
    } else {
        $data['category_description'] = array();
    }



    foreach ($this->request->post['category_description'] as  $value) {

        if ((utf8_strlen($value['meta_title']) < 3) || (utf8_strlen($value['meta_title']) > 255)) {
            $this->error['meta_title'] = $this->language->get('error_meta_title');
        }

    }

model\post\category.php

public function getCategoryDescriptions($category_id) {
    $category_description_data = array();

    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_description WHERE category_id = '" . (int)$category_id . "'");

    foreach ($query->rows as $result) {
        $category_description_data[] = array(
            'meta_title'       => $result['meta_title'],
            'meta_description' => $result['meta_description'],
            'meta_keyword'     => $result['meta_keyword'],
            'description'      => $result['description']
        );
    }

    return $category_description_data;
}



                <div class="row mt-3 required">
                    <label class="col-sm-2 col-form-label"
                           for="input-meta-title"><?php echo $entry_meta_title; ?></label>
                    <div class="col-sm-10">
                        <div class="input-group">
                            <span class="input-group-text"><?php echo $text_required; ?></span>
                            <input type="text"
                                   name="category_description[meta_title]"
                                   value="<?php echo isset($category_description['meta_title']) ? $category_description['meta_title'] : ''; ?>"
                                   placeholder="<?php echo $entry_meta_title; ?>"
                                   id="input-meta-title"
                                   class="form-control"/>
                        </div>
                        <?php if ($error_meta_title) { ?>
                        <div class="text-danger pt-2">
                            <?php echo $error_meta_title; ?></div>
                        <?php } ?>
                    </div>
                </div>
1

There are 1 answers

0
K. B. On

Add:

print_r($this->request->post); die;

Before:

foreach ($this->request->post['category_description'] as  $value) {

and check what is being posted. Seems meta_title is not posted.