Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jinmarcus opened this issue Oct 13, 2017 · 1 comment

Comments

@jinmarcus
Copy link

jinmarcus commented Oct 13, 2017

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?

@lonnieezell
Copy link
Member

Please take non-bug questions to the forums. Github is for bug-tracking and feature development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants