[SOLVED] CI4 - Unable to Autoload Markdown Class |
I am in the process of trying to use CI4 for an existing PHP program that utilises MarkDown.
In accordance with the CI4 Manual I have added the following to /app/Config/Autoload.php PHP Code: /* Files available: Unfortunately I am unable to use CI4 way of using Markdown I can only get it to work using require_once('Class_MarkDown.php); ... ...as can be seen in the following class: PHP Code: <?php
Did you install markdown using Composer? Is so, and if I understand correctly, then you do not need to add anything to /app/Config/Autoload.php. Doing so may be the source of your problem.
CI4 is hardwired to use the composer autoloader which will work just fine in conjunction with the C4 autoloader. Using require_once is only appropriate when not using an autoloader.
I did not use Composer for the installation.
I downloaded and saved Markdown into my common library folder. I expected when running CI4 it would autoload the required Markdown library and I would be able to use the Markdown methods.
If you are going to copy files into the app/Libraries folder, they might need to be namespaced App\Libraries in order for CI4 to find them automatically.
> @ ciadmin
> If you are going to copy files into the app/Libraries folder, they might need to be namespaced App\Libraries in order for CI4 to find them automatically. Many thanks, it is now too late for me to try tonight, looking forward to trying tomorrow.
Unfortunately I could not get namespace to work and I did try for well over an hour
I would be grateful if someone could supply a very simple example of the correct way to use config/Autoload.php and to set the Markdown namespace and use statement. Girhub Repository: https://github.com/michelf/php-markdown
The problem is that the files themselves have a namespace, Michelf. So the class Markdown doesn't actually exist.
The simplest way would be composer. If you don't want to use that you can use CI's autoload and let it know the namespace and where it's located. In app/Config/Autoload.php: Code: $psr4 = [
@ kilishan - Many thanks for the prompt reply.
I am now able correctly to use the https://github.com/michelf/php-markdown library. Perhaps amend the CI4 User Guide would prevent others making the same mistake. https://codeigniter4.github.io/CodeIgnit...t=markdown
For those who would like to try the following Markdown Github Repository:
https://github.com/michelf/php-markdown 1. Github clone or download into a \any\folder\of\your\choice\ 2. Amend this file: app/Config/Autoload.php PHP Code: // ORIGINAL 3. Markdown Class: PHP Code: <?php
Thanks for the follow up to your experience! I’d also add that since this ultimately was a namespace mistake, really the best way to use it in CI4 is to install it via Composer:
cd CI/root/dir composer require michelf/php-markdown And that’s it! There may be reasons OP and others would want a separate folder, but this is really the way CI4 was designed. |
Welcome Guest, Not a member yet? Register Sign In |