CodeIgniter Forums
Moving to ci4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: Moving to ci4 (/showthread.php?tid=87908)



Moving to ci4 - richb201 - 06-17-2023

It has been a number of years but I am ready to move my app from ci3 to ci4. I realize this will be a rewrite. 

But first I need to learn ci4.  Can anyone recommend a way to learn CI4? Is reading the documentation the way to go?


RE: Moving to ci4 - iRedds - 06-17-2023

1. learn php (namespace priority)
2. documentation
3. source code


RE: Moving to ci4 - richb201 - 06-17-2023

Thx. Can you point at an example? I already know php slightly. What is namespace priority? Where can I review that? What documentation are you referring to?


RE: Moving to ci4 - iRedds - 06-17-2023

https://www.php.net/manual/en/language.namespaces.rationale.php


RE: Moving to ci4 - kenjis - 06-17-2023

Yes, first of all, everyone should learn modern PHP, especially namespaces and autoloading (PSR-4).
https://phptherightway.com/#namespaces
https://leanpub.com/codeigniter4foundations "Primer: Namespaces"
https://www.php-fig.org/psr/psr-4/
And it is better to learn Composer.
https://phptherightway.com/#composer_and_packagist

Next read the upgrade guide.
https://codeigniter4.github.io/CodeIgniter4/installation/upgrade_4xx.html

"CodeIgniter 3 to 4 Upgrade Helper" might help you.
https://github.com/kenjis/ci3-to-4-upgrade-helper#readme


RE: Moving to ci4 - InsiteFX - 06-17-2023

Read the CodeIgniter Documentation also.

IncludeBeer - CodeIgniter 4 Tutorials.

Search Google for other Tutorials.


RE: Moving to ci4 - richb201 - 06-20-2023

Thanks. With some help I managed to get ci4 and a debugger running under phpstorm. I am going to try to roughly get my ci3 app running under ci4. My app uses GroceryCrud heavily.

My main controller called Configure.php starts with __construct() where I load up a few helpers and libraries, get the results of authentication from Okta, run _init() which set up session variables and finally index().

My question is where do I do the initialization/sessionSetup/authetication now? Do I do this in the BaseController?

(06-20-2023, 03:20 PM)richb201 Wrote: Thanks. With some help I managed to get ci4 and a debugger running under phpstorm. I am going to try to roughly get my ci3 app running under ci4. My app uses GroceryCrud heavily.

Under ci3 my main controller called Configure.php starts with __construct() where I load up a few helpers and libraries, get the results of authentication from Okta, run _init() which set up session variables and finally index().

My question is where do I do the initialization/sessionSetup/authetication now? Do I do this in the BaseController?



RE: Moving to ci4 - InsiteFX - 06-20-2023

Yes the BaseController is where I setup my Sessions.

PHP Code:
<?php

namespace App\Controllers;

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

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *    class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 */
abstract class BaseController extends Controller
{
    /**
    * Instance of the main Request object.
    *
    * @var CLIRequest|IncomingRequest
    */
    protected $request;

    /**
    * An array of helpers to be loaded automatically upon
    * class instantiation. These helpers will be available
    * to all other controllers that extend BaseController.
    *
    * @var array
    */
    protected $helpers = [];

    /**
    * Be sure to declare properties for any property fetch you initialized.
    * The creation of dynamic property is deprecated in PHP 8.2.
    */
    protected $session;

    /**
    * Constructor.
    */
    public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request$response$logger);

        // Preload any models, libraries, etc, here.

        // E.g.: $this->session = \Config\Services::session();
        // Ensure that the session is started and running
        if (session_status() == PHP_SESSION_NONE) {
            $this->session Services::session();
        }

    }

    // -------------------------------------------------------------------

}  // End of Class BaseController.

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



RE: Moving to ci4 - richb201 - 06-21-2023

Thanks Insite. It has been awhile. I am trying to setup BaseController. I am on the helpers section:

protected $helpers = [];

So I tried this:

helper(array('form', 'url', 'file', 'array', 'download', 'directory', 'cookie','date'));

I want to get started on the "right foot". Docs show:

helper('array');

Is that not what I am doing?


RE: Moving to ci4 - kenjis - 06-21-2023

See https://codeigniter4.github.io/CodeIgniter4/general/helpers.html