Welcome Guest, Not a member yet? Register   Sign In
Moving to ci4
#1

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?
proof that an old dog can learn new tricks
Reply
#2

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

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?
proof that an old dog can learn new tricks
Reply
Reply
#5

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/CodeIgnit...e_4xx.html

"CodeIgniter 3 to 4 Upgrade Helper" might help you.
https://github.com/kenjis/ci3-to-4-upgra...per#readme
Reply
#6

Read the CodeIgniter Documentation also.

IncludeBeer - CodeIgniter 4 Tutorials.

Search Google for other Tutorials.
What did you Try? What did you Get? What did you Expect?

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

(This post was last modified: 06-20-2023, 03:21 PM by richb201.)

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?
proof that an old dog can learn new tricks
Reply
#8

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
 * ----------------------------------------------------------------------- 
What did you Try? What did you Get? What did you Expect?

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

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?
proof that an old dog can learn new tricks
Reply
#10

See https://codeigniter4.github.io/CodeIgnit...lpers.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB