Welcome Guest, Not a member yet? Register   Sign In
Can't create a working CI4 project after 4.3.8 and 4.4
#1

(This post was last modified: 08-26-2023, 07:54 AM by gosocial2. Edit Reason: Improved syntax highlighting using the correct tags )

Hello guys,
Thrilled with the announcement of CodeIgniter 4.3.8 and 4.4.0, I went ahead and tried to experiment with it. 
To be safe, I opted in to create a new project based on 4.3.8 rather than trying to update my existing ones.

What I did:

I fired up a Terminal and typed in

Code:
composer create-project codeigniter4/appstarter:4.3.8 ci438

At first, I didn't pay much attention what exact version Composer spitted out, as in most cases things go as expected given my PHP and Composer versions are right. But I repeated this step in the end as you will see towards the bottom of this post.

Then

Code:
php spark serve

Fatal error: Uncaught Error: Undefined constant "CodeIgniter\ENVIRONMENT" in /Users/dev/CI4projs/ci438/vendor/codeigniter4/framework/system/CodeIgniter.php on line 581

Error: Undefined constant "CodeIgniter\ENVIRONMENT" in /Users/dev/CI4projs/ci438/vendor/codeigniter4/framework/system/CodeIgniter.php on line 581

Call Stack:
    0.0011    410760  1. {main}() /Users/dev/CI4projs/ci438/spark:0
    0.0224    2453008  2. CodeIgniter\CodeIgniter->initialize() /Users/dev/CI4projs/ci438/spark:83
    0.0224    2453008  3. CodeIgniter\CodeIgniter->bootstrapEnvironment() /Users/dev/CI4projs/ci438/vendor/codeigniter4/framework/system/CodeIgniter.php:203

The class in question (i.e. CodeIgniter.php) has:
PHP Code:
/**
 * This class is the core of the framework, and will analyse the
 * request, route it to a controller, and send back the response.
 * Of course, there are variations to that flow, but this is the brains.
 */
class CodeIgniter
{
    /**
    * The current version of CodeIgniter Framework
    */
    public const CI_VERSION '4.4.0';
// ... 

It turns out that my extra arguments to enforce pulling 4.3.8 did not work, or the composer repositories holds a messed up "CodeIgniter 4.3.8 version mixed with 4.4.0 files".

I also tried:

Code:
composer create-project codeigniter4/appstarter ci438alt "4.3.8"

The above does not produce a different result when I execute "php spark serve". To be sure I ultimately ran the below.

Code:
% php -v
PHP 8.1.20 (cli) (built: Jun 15 2023 05:42:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.20, Copyright (c) Zend Technologies
    with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans
    with Zend OPcache v8.1.20, Copyright (c), by Zend Technologies

% composer -V
Composer version 2.5.2 2023-02-04 14:33:22

% composer create-project codeigniter4/appstarter:4.3.8 ci438clean
Creating a "codeigniter4/appstarter:4.3.8" project at "./ci438clean"
Installing codeigniter4/appstarter (v4.3.8)
  - Installing codeigniter4/appstarter (v4.3.8): Extracting archive
Created project in /Users/dev/CI4projs/ci438clean
Loading composer repositories with package information
Updating dependencies
Lock file operations: 35 installs, 0 updates, 0 removals
  - Locking codeigniter4/framework (v4.4.0) <<<<<<<<<<<<<<<<<<<<<<<<<<< PROBLEM HERE
  - Locking doctrine/instantiator (2.0.0)
  - Locking fakerphp/faker (v1.23.0)
  - Locking laminas/laminas-escaper (2.12.0)
  - Locking mikey179/vfsstream (v1.6.11)
  - Locking myclabs/deep-copy (1.11.1)
  - Locking nikic/php-parser (v4.17.1)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.2.1)
  - Locking phpunit/php-code-coverage (9.2.27)
  - Locking phpunit/php-file-iterator (3.0.6)
  - Locking phpunit/php-invoker (3.1.1)
  - Locking phpunit/php-text-template (2.0.4)
  - Locking phpunit/php-timer (5.0.3)
  - Locking phpunit/phpunit (9.6.11)
  - Locking psr/container (2.0.2)
  - Locking psr/log (1.1.4)
  - Locking sebastian/cli-parser (1.0.1)
  - Locking sebastian/code-unit (1.0.8)
  - Locking sebastian/code-unit-reverse-lookup (2.0.3)
  - Locking sebastian/comparator (4.0.8)
  - Locking sebastian/complexity (2.0.2)
  - Locking sebastian/diff (4.0.5)
  - Locking sebastian/environment (5.1.5)
  - Locking sebastian/exporter (4.0.5)
  - Locking sebastian/global-state (5.0.6)
  - Locking sebastian/lines-of-code (1.0.3)
  - Locking sebastian/object-enumerator (4.0.4)
  - Locking sebastian/object-reflector (2.0.4)
  - Locking sebastian/recursion-context (4.0.5)
  - Locking sebastian/resource-operations (3.0.3)
  - Locking sebastian/type (3.2.1)
  - Locking sebastian/version (3.0.2)
  - Locking symfony/deprecation-contracts (v3.3.0)
  - Locking theseer/tokenizer (1.2.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 35 installs, 0 updates, 0 removals
  - Installing psr/log (1.1.4): Extracting archive
  - Installing laminas/laminas-escaper (2.12.0): Extracting archive
  - Installing codeigniter4/framework (v4.4.0): Extracting archive
  - Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing fakerphp/faker (v1.23.0): Extracting archive
  - Installing mikey179/vfsstream (v1.6.11): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (3.2.1): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.5): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.6): Extracting archive
  - Installing sebastian/exporter (4.0.5): Extracting archive
  - Installing sebastian/environment (5.1.5): Extracting archive
  - Installing sebastian/diff (4.0.5): Extracting archive
  - Installing sebastian/comparator (4.0.8): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing nikic/php-parser (v4.17.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.27): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.1): Extracting archive
  - Installing doctrine/instantiator (2.0.0): Extracting archive
  - Installing phpunit/phpunit (9.6.11): Extracting archive
9 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
27 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
I'll appreciate if anyone lets me know if I'm missing anything here.

CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5)

Reply
#2

(This post was last modified: 08-26-2023, 09:24 AM by captain-sensible. Edit Reason: extra extra )

what does the file composer.json show is it :

Code:
"codeigniter4/framework": "^4.0"

if you want specifically 4.3.8 then try deleting any composer.json lock file . edit to :
Code:
"codeigniter4/framework": "4.3.8"

then from memory change directory of terminal to your web root and run :
Code:
composer install   --no-dev
or
composer install
CMS CI4     I use Arch Linux by the way 

Reply
#3

I may be wrong, but appstarter always uses the latest version. You are trying to install a version of the framework, but choose appstarter
Reply
#4

Yes, appstarter always installs the latest version of the framework.
See https://github.com/codeigniter4/appstart...r.json#L14

There is no official way to install past version with appstarter.
But you can do it with the following script:
https://github.com/kenjis/ci4-composer-installer
Reply
#5

Captain-sensible's recommendation worked:

Code:
composer require codeigniter4/framework:4.3.8


But I will also be trying kenjis's ci4-composer-installer next time.

CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5)

Reply
#6

(This post was last modified: 09-01-2023, 04:31 AM by Muzikant.)

I had the same problem.

  1. At the beginning, create a backup of your web application folder (root)!
  2. Now work with your development folder and run Composer update on it. On your composer.json file you should require latest CI4:
    Code:
    "codeigniter4/framework": "^4.0"
  3. Replace these files:
    vendor/codeigniter/framework/spark.php > spark.php
    vendor/codeigniter/framework/public/index.php > public/index.php
  4. Copy this file:
    vendor/codeigniter/framework/app/Config/Routing.php > app/Config/
  5. You will need to combine your personal settings from app/Config/Routes.php with new version located in vendor/codeigniter/framework/app/Config/Routes.php, which now should looks like this:
    PHP Code:
    <?php

    use CodeIgniter\Router\RouteCollection;

    /**
     * @var RouteCollection $routes
     */
    $routes->get('/''Home::index');
    // all your personal routes from old file belongs here 
  6. You should combine all of your individual personal settings from old config files combine with new config files as you did step 5.
  7. Restart PHP server and try if your web application is working.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB