Skip to content

I wish I could call the $this of the controller in the business model. What's the solution? #774

Description

@jinmarcus

I wish I could call the $this of the controller in the business model. What's the solution?
I want to write only basic access logic in the controller, and business logic in the business model Events

controller like this

namespace App\Controllers;
use App\Events\MyEvent;
class My extends \CodeIgniter\Controller {

        protected $helpers = ['common', 'url'];
        
	public function __construct(...$params) {
		parent::__construct(...$params);

	       $this->mydate = 'test';
               $this->db = \Config\Database::connect();
               $this->db->initialize();

               $this->form = \Config\Services::validation();
               
              $this->myEvent = new  MyEvent();
	}
        
	public function index() {
		return $this->myEvent->getTest();
	}
}

events like this

use App\Events;
class MyEvent {
	public function getTest() {
               
               // How can I use the $this in the controller here?
              // Such as:  $this->db->table('')....
              //           $this->form->withRequest($this->request)->run()...
              //           $this->mydate
	}
}

What do I do?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions