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

How to use Controller own constructer? #1208

Closed
byazrail opened this issue Sep 8, 2018 · 7 comments
Closed

How to use Controller own constructer? #1208

byazrail opened this issue Sep 8, 2018 · 7 comments

Comments

@byazrail
Copy link
Contributor

byazrail commented Sep 8, 2018

<?php	
class Blog extends \CodeIgniter\Controller	
{	
	public function __construct(...$params)	
	{	
		parent::__construct(...$params);	
		// Your own constructor code	
	}	
}

not be use __construct

@byazrail
Copy link
Contributor Author

byazrail commented Sep 8, 2018

Ref changed controller;
f4c373e

@jim-parry
Copy link
Contributor

Support questions should be asked on the forum, thanks.
We use github for bug tracking & work packages.

@lonnieezell
Copy link
Member

Unless this is referencing someplace in the docs that I missed changing, in which case you should mention that....

@byazrail
Copy link
Contributor Author

byazrail commented Sep 8, 2018

@lonnieezell hi,

CRITICAL - 2018-09-08 18:09:22 --> Cannot call constructor
#0 /Users/byazrail/Desktop/www/dev10.net/ThirdParty/Site/Controllers/Site.php(7): App\Core\SiteController->__construct(Array)
#1 /Users/byazrail/Desktop/www/dev10.net/core/CodeIgniter.php(782): Site\Controllers\Site->__construct()
#2 /Users/byazrail/Desktop/www/dev10.net/core/CodeIgniter.php(842): CodeIgniter\CodeIgniter->createController()
#3 /Users/byazrail/Desktop/www/dev10.net/core/CodeIgniter.php(234): CodeIgniter\CodeIgniter->display404errors(Object(CodeIgniter\Exceptions\PageNotFoundException))
#4 /Users/byazrail/Desktop/www/dev10.net/public/index.php(48): CodeIgniter\CodeIgniter->run()
#5 /Users/byazrail/Desktop/www/dev10.net/rewrite.php(49): require_once('/Users/byazrail...')
#6 {main}

own extend core controller create __construct not found replaced initController.
How to use own controller extended?

@lonnieezell
Copy link
Member

If you'll look at the commit you referenced, you'll see the Controller's constructor was removed. So there's no parent::__construct() to call. Hence the error saying it cannot call the constructor. Remove the call parent::__construct call and you're good to go.

Now - was there somewhere in the current docs you got that from, or was that old code?

@byazrail
Copy link
Contributor Author

byazrail commented Sep 8, 2018

Old codes;
See user guide;
System Class List
The following is a list of the core system files that are invoked every time CodeIgniter runs:

  • CodeIgniter\Controller

If you are extending the Controller core class, then be sure to extend your new class in your application controller’s constructors:
`class Home extends App\BaseController {

}`

My code extends SiteController;
`namespace App\Core;

class SiteController extends \CodeIgniter\Controller
{
protected $langData;
protected $session;
protected $themeKey;
public $userSessionData = false;

public function __construct(array $param = [], ...$params)
{
    parent::__construct(...$params);

    // Your own constructor code
    helper(['url', 'form', 'functions', 'cookie', 'Site\site']);

	\Config\Database::connect();
	$this->session	= \Config\Services::session();

	$this->response->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', time()) .' GMT')
					->setHeader('Content-Type', 'text/html; charset=UTF-8');`

.....

Normal Controller And Extends SiteControllers;
`
namespace Site\Controllers;

class Site extends \App\Core\SiteController
{
public function __construct(...$params)
{
parent::__construct(['forceHttps' => false], ...$params);

    // Autoloads
}`

.......

Extends controllers own controllers $this->response, $this->request how access ?
Codeigniter\Controller not __construct :)
I have temporarily returned to the old code.

Have a nice day.

@byazrail
Copy link
Contributor Author

byazrail commented Sep 8, 2018

code restyle bad. attach screens;
screen shot 2018-09-08 at 21 40 53
screen shot 2018-09-08 at 21 41 17

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

3 participants