Welcome Guest, Not a member yet? Register   Sign In
require Codeigniter's public/index.php to use in existing PHP project.
#1

Hi,
I would like to integrate an existing CodeIgniter4 Project into another existing PHP project for migration purposes.
The simplest idea I could come up with was to simply include / require the public/index.php of the Codeiginiter Setup.
CodeIgniter would still use its router and all services, but within another application.

Let me describe my (minimized) setup:

I have a standard codeigniter4 project in /webroot/codeigniter.
I have a PHP file /webroot/index.php that simply requires the public/index.php with the content
PHP Code:
<?php

require __DIR__ '/codeigniter/public/index.php'

?>
This results in the following error:

Call to a member function shouldDiscover() on null
/vendor/codeigniter4/framework/system/Config/BaseService.php: 37

I'm unsure how to fix this. I suspect this could be a path issue, but since we can find BaseService.php, this seems to work reasonably fine.
Here are my questions:

1. What do I have to fix to make this work?
2. Is this a reasonable approach at all? Are there better ways to "integrate" a CodeIgniter Application into existing PHP infastructure?
3. Do you know of any guides how to accomplish such a task?
Reply
#2

Such integration is generally more difficult.

However, your sample should work.

I installed CI4 to htdocs/ci442,
and I put htdocs/index.php.

PHP Code:
<?php
require __DIR__ '/ci442/public/index.php'

I can see the "Welcome to CodeIgniter 4.4.2" page.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB