Delete users success but delete articles failed

I have problem to remove articles, if I’m remove users success but if I’m remove articles was failed, the message error shown

Notice (1024): Undefined property: ErrorController::$Auth in C:\xampp\htdocs\klinikucing\src\Controller\AppController.php on line 49 [CORE\src\Controller\Controller.php, line 388]

Warning (512): Unable to emit headers. Headers sent in file=C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php line=853 [CORE\src\Http\ResponseEmitter.php, line 48]

Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 148]

Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]

Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]

An Internal Server Error Occurred

sample code in users table if I’m delete success working

<?php
namespace App\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Rule\IsUnique;
use Cake\ORM\Table;
use Cake\Validation\Validator;

class UsersTable extends Table
{

    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('users');
        $this->setDisplayField('ID');
        $this->setPrimaryKey('ID');

        $this->hasMany('Articles', [
            'foreignKey' => 'user_id'
        ]);
    }
}
?>

in UsersController that I was success delete

<?php
namespace App\Controller;

use App\Controller\AppController;
use App\Model\Table\UsersTable;
use Cake\Event\event;
use Cake\I18n\Time;
use Cake\ORM\TableRegistry;
use Cake\Network\Request;

class UsersController extends AppController
{
	public function beforeFilter(Event $event)
	{
		parent::beforeFilter($event);
		$this->Auth->allow(['logout', 'add']);
	}
       
        public function delete($id = null)
        {
           $this->request->allowMethod(['post', 'delete']);
           $user = $this->Users->get($id);
           if ($this->Users->delete($user)) {
              $this->Flash->success(__('Pengguna berhasil dihapus.'));
           } else {
             $this->Flash->error(__('Pengguna gagal dihapus, Coba lagi.'));
        }
        return $this->redirect(['action' => 'index']);
}
?>

this ArticlesTable that I don’t know cause error delete

<?php
namespace App\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Rule\IsUnique;
use Cake\ORM\Table;
use Cake\Validation\Validator;

class ArticlesTable extends Table
{

    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('articles');
        $this->setDisplayField('Judul');
        $this->setPrimaryKey('ID');

        $this->belongsTo('Users', [
            'foreignKey' => 'user_id'
        ]);
        $this->hasMany('Comments', [
            'foreignKey' => 'article_id'
        ]);
        $this->belongsToMany('Tags', [
            'targetForeignKey' => 'tag_id',
			'foreignKey' => 'article_id',
			'joinTable' => 'articles_tags'
        ]);
    }

    public function buildRules(RulesChecker $rules)
    {
        $rules->add($rules->existsIn(['user_id'], 'Users'));

        return $rules;
    }
}
?>

and this ArticlesController is a part I don’t know cause error delete

<?php
namespace App\Controller;

use App\Controller\AppController;
use App\Model\Table\ArticlesTable;
use Cake\Event\event;
use Cake\I18n\Time;
use Cake\ORM\TableRegistry;
use Cake\Network\Request;

class ArticlesController extends AppController
{
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $article = $this->Articles->get($id);
        if ($this->Articles->delete($article)) {
            $this->Flash->success(__('Artikel berhasil dihapus.'));
        } else {
            $this->Flash->error(__('Artikel gagal dihapus, coba lagi.'));
        }

        return $this->redirect(['action' => 'index']);
    }

    public function isAuthorized($user)
	{
		//sebelum 3.4.0 param('parameter') digunakan
		if ($this->request->getParam('action') === 'add') {
			return true;
		}
		
		if (in_array($this->request->getParam('action'), ['edit', 'delete'])) {
			$articleID = (int)$this->request->getParam('pass.0');
			if ($this->Articles->isOwnedBy($articleID, $user['ID'])) {
				return true;
			}
		}
		return parent::isAuthorized($user);
	}
}
?>

and this in Articles index.ctp

<tr>
    <td colspan="9"><i class="fa fa-user" style="font-size:20px;"></i> &nbsp; <?php echo $userInfo["Nama"]; ?> &nbsp; <i class="fa fa-long-arrow-right" style="font-size:17px;"></i> &nbsp; <?php echo $userInfo["Role"]; ?></td>
</tr>

<?php echo $this->Html->link(__('Hapus'), ['action' => 'delete', $article->ID], ['confirm' => __('Yakin ingin menghapus # {0}', $article->Judul)]);?>

error location in AppController line 49, here this

<?php
namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Event\Event;


class AppController extends Controller
{
	
    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('RequestHandler', [
            'enableBeforeRedirect' => false,
        ]);
		$this->loadComponent('Flash');
        //panggil plugin kucing
		$this->viewBuilder()->theme('Kucing');
		//authenticate
		$this->loadComponent('Auth', [
			'authenticate' => [
				'Form' => [
					'fields' => [
						'username' => 'Email',
						'password' => 'Password'
					]
				]
			],
			'loginAction' => [
				'controller' => 'Users',
				'action' => 'login'
			],
			//jika tidak sah, maka alihkan
			'unauthorizedRedirect' => $this->referer()
		]);
		//izinkan mode membaca
		$this->Auth->allow(['beranda', 'view', 'index']);
	}
	
	public function beforeFilter(Event $event)
	{
		$this->Auth->allow(['beranda', 'view', 'index']);
	}
	
	public function beforeRender(Event $event)
	{
		parent::beforeFilter($event);
		$this->set('userInfo', $this->Auth->user()); // in UsersTable record success delete, but in ArticlesTable record failed to delete
	}
}
?>

I hopefull someone give me help, thanx

whats your code of ErrorController ?

also your

<?php echo $this->Html->link(__('Hapus'), ['action' => 'delete', $article->ID], ['confirm' => __('Yakin ingin menghapus # {0}', $article->Judul)]);?>

it uses GET method and you allow only $this->request->allowMethod(['post', 'delete']); might be related, there is https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-post-links for POST method

Why haven’t you set an “on delete” with your foreign key?
That way, when you delete the user, it’ll delete the articles associated with said user.