• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
hijacking \CodeIgniter\Controller

#1
Hi.
Can anyone give an example, how to hijack \Codeigniter\Controllet as MY_Controller in version 3
Reply

#2
The base controller:

PHP Code:
<?php namespace App\Controllers;

/**
 * ---------------------------------------------------------------------------
 * Editor   : PhpStorm 2016.3.2
 * Date     : 6/29/2017
 * Time     : 10:22 AM
 * Authors  : Raymond L King Sr.
 * ---------------------------------------------------------------------------
 * 
 * Class        BaseController
 * 
 * @project     ci4
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2017 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ---------------------------------------------------------------------------
 */

use CodeIgniter\Controller;

/**
 * Class BaseController
 *
 * @package App\Controllers
 */
class BaseController extends Controller
{
    
/**
     * Class variables - public, private, protected and static.
     * -----------------------------------------------------------------------
     */

    /**
     * @var  array
     */
    
protected $helpers = [];

    
/**
     * __construct ()
     * -----------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {
 
       // Ensure session is started and running
 
       if (session_status() == PHP_SESSION_NONE)
 
       {
 
           // session has not started so start it
 
           session()->start();
 
       }
    }

  // End of BaseController Class.

/**
 * ---------------------------------------------------------------------------
 * Filename: BaseController.php
 * Location: ./application/Controllers/BaseController.php
 * ---------------------------------------------------------------------------
 */ 

The Admin controller:

PHP Code:
<?php namespace App\Controllers;

/**
 * ---------------------------------------------------------------------------
 * Editor   : PhpStorm 2016.3.2
 * Date     : 6/29/2017
 * Time     : 10:22 AM
 * Authors  : Raymond L King Sr.
 * ---------------------------------------------------------------------------
 * 
 * Class        AdminController
 * 
 * @project     ci4
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2017 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ---------------------------------------------------------------------------
 */


/**
 * Class AdminController
 *
 * @package App\Controllers\Base
 */
class AdminController extends BaseController
{
    
/**
     * Class variables - public, private, protected and static.
     * -----------------------------------------------------------------------
     */

    /**
     * __construct ()
     * -----------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {
        
parent::__construct();
    }

  // End of AdminController Class.

/**
 * ---------------------------------------------------------------------------
 * Filename: AdminController.php
 * Location: ./application/Controllers/AdminController.php
 * ---------------------------------------------------------------------------
 */ 

The Public controller:

PHP Code:
<?php namespace App\Controllers;

/**
 * ---------------------------------------------------------------------------
 * Editor   : PhpStorm 2016.3.2
 * Date     : 6/29/2017
 * Time     : 10:22 AM
 * Authors  : Raymond L King Sr.
 * ---------------------------------------------------------------------------
 * 
 * Class        PublicController
 * 
 * @project     ci4
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2017 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ---------------------------------------------------------------------------
 */


/**
 * Class PublicController
 *
 * @package App\Controllers\Base
 */
class PublicController extends BaseController
{
    
/**
     * Class variables - public, private, protected and static.
     * -----------------------------------------------------------------------
     */


    /**
     * __construct ()
     * -----------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {
        
parent::__construct();
    }

  // End of PublicController Class.

/**
 * ---------------------------------------------------------------------------
 * Filename: PublicController.php
 * Location: ./application/Controllers/PublicController.php
 * ---------------------------------------------------------------------------
 */ 

Is that what your looking for?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
When I add script
parent::_construct() 
in baseController, why do I get Error 500?
Reply

#4
There is no CodeIgniter __construct in the Controller anymore.

Leave the parent::__construct() out.

If you look at system Controller.php you will see that there is no constructor method

It's added to the BaseController for passing parameters to the other controllers.

Also remove the helpers ad the begging of the BaseController it is in the Controller now.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(09-24-2018, 09:37 AM)InsiteFX Wrote: There is no CodeIgniter __construct in the Controller anymore.

Leave the parent::__construct() out.

If you look at system Controller.php you will see that there is no constructor method

It's added to the BaseController for passing parameters to the other controllers.

Also remove the helpers ad the begging of the BaseController it is in the Controller now.

Many thanks for your explanation.
Reply

#6
I found this script from Killishan's blog and your pdf. 

Code:
class Home extends \CodeIgniter\Controller
{
public function __construct(...$params)
{
parent::__construct(...$params);
// This controller is only accessible via HTTPS
if (! $this->request->isSecure())
{
// Redirect the user to this page via HTTPS, and set the Strict-
Transport-Security
// header so the browser will automatically convert all links to this
page to HTTPS
// for the next year.
force_https();
}
}
Reply

#7
That is old code, the controller has been changed since that was written.

The controller doe's not pass the $params anymore.

Look at the System Controller code and you will see the change
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.