Why do I get undefined index for this code whenever I click the delete button?

Why do I get undefined index for this code whenever I click the button?

[php7:notice] PHP Notice:  Trying to access array offset on value of type null in /var/www/.../public_html/app/Helper/LayoutHelper.php on line 90
[php7:notice] PHP Notice:  Undefined index: project in /var/www/.../public_html/app/Helper/LayoutHelper.php on line 91

I click this in a button:

<a href="<?= $this->url->href('ContactsItemsController', 'confirm', array('item_id' => $item['id'], 'plugin' => 'AddressBook'), false, '', false) ?>" class="btn btn-ab-delete js-modal-medium" title="<?=t('Delete Property') ?>">
<i class="fa fa-trash-o" aria-hidden="true"></i> <?= t('Delete') ?>
</a>

I read that isset is a solution but if using isset is the solution, where do I place it? I can’t figure it out.

I tried:

<a href="<?= $this->url->href('ContactsItemsController', 'confirm', array('item_id' => isset($item['id']), 'plugin' => 'AddressBook'), false, '', false) ?>" class="btn btn-ab-delete js-modal-medium" title="<?=t('Delete Property') ?>">
<i class="fa fa-trash-o" aria-hidden="true"></i> <?= t('Delete') ?>
</a>

But that never worked. Also, it is suggesting project in the error, and there is no mention of project in the code. The function of the actual code works fine.

Line 90-91 that the error is referring to is the elseif part of the below function:

public function project($template, array $params, $sidebar = 'project/sidebar')
    {
        if (empty($params['title'])) {
            $params['title'] = $params['project']['name'];
        } elseif ($params['project']['name'] !== $params['title']) {
            $params['title'] = $params['project']['name'].' &gt; '.$params['title'];
        }

        return $this->subLayout('project/layout', $sidebar, $template, $params);
    }

Any help will be appreciated. I created an issue for the upcoming plugin here:

Your issue arrises with what you are sending as the param var to the helper.

Your array contains no refernce to project

oh hello…

okay but thats because project is not needed?

oh… do you think the layout should be config instead of project? its only a modal

Thats up to you, but whether its needed or not, if you use that helper function its a requirement.

1 Like

Going back to isset question.

You are not using it correctly, so thats why it doesnt ever work for you. Its a boolean. When you use it, you are asking a question, then its up to you to tell the code what to do if its true and its false. Just putting isset in front of the variable, all you are doing is sending a true or false, which is pointless.

Example:

Isset?

Yes, do this.

No, do something else.

1 Like

thanks, I think the project to config in the layout fixed it