Welcome Guest, Not a member yet? Register   Sign In
public function __construct()
#1

PHP Code:
public function __construct()
{
     parent::__construct();
     $this->load->model('youth_user_model');
 
     $this->load->helper('url');
 
     $this->load->helper('html');
}


I am trying to convert a site  from version 3 to 4 of codeigniter

I am getting cannot call constructor on line 10
Line 10 is parent
::__construct();truct()();

What should that bit of code look like for version 4 please? Do I just remove that lineThanks 
Reply
#2

PHP Code:
All of these will load your helpers.

helper(['url''html']);

protected 
$helpers = ['url''htnl'];

Auto-loading Helpers
New in version 4.3.0.

If 
you find that you need a particular helper globally throughout your application
you can tell CodeIgniter to auto-load it during system initialization.
This is done by opening the app/Config/Autoload.php file and adding the helper to 
the $helpers property

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 01-16-2024, 01:47 PM by adimancifi.)

I hope this work for you.

CodeIgniter v3.x
PHP Code:
class Home extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        
        $this
->load->model('youth_user_model');
        $this->load->helper('url');
        $this->load->helper('html');
    }
    
    
public function index()
    {
        return $this->load->view('home');
    }




CodeIgniter v4.4.4

PHP Code:
namespace App\Controllers;

use 
Config\Services;
use 
CodeIgniter\HTTP\CLIRequest;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Psr\Log\LoggerInterface;

class 
Home extends BaseController 
{
    public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        parent::initController($request$response$logger);
        
        $this
->youth_user_model model('youth_user_model');
        helper(['url','html']);
    }
    
    
public function index()
    {
        return view('home');
    }

Reply
#4

See https://codeigniter4.github.io/CodeIgnit...e_4xx.html
Reply
#5

Thanks the last one was what I was looking for
Reply




Theme © iAndrew 2016 - Forum software by © MyBB