![]() |
[SOLVED] CI4 - Unable to Autoload Markdown Class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: [SOLVED] CI4 - Unable to Autoload Markdown Class (/showthread.php?tid=73458) Pages:
1
2
|
[SOLVED] CI4 - Unable to Autoload Markdown Class - John_Betong - 04-26-2019 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 RE: CI4 - Unable to Autoload Markdown Class - dave friend - 04-26-2019 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. RE: CI4 - Unable to Autoload Markdown Class - John_Betong - 04-26-2019 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. RE: CI4 - Unable to Autoload Markdown Class - ciadmin - 04-26-2019 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. RE: CI4 - Unable to Autoload Markdown Class - John_Betong - 04-26-2019 > @ 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. RE: CI4 - Unable to Autoload Markdown Class - John_Betong - 04-26-2019 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 RE: CI4 - Unable to Autoload Markdown Class - kilishan - 04-26-2019 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 = [ RE: CI4 - Unable to Autoload Markdown Class - John_Betong - 04-27-2019 @ 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/CodeIgniter4/concepts/autoloader.html?highlight=markdown RE: CI4 - Unable to Autoload Markdown Class - John_Betong - 04-27-2019 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 RE: [SOLVED] CI4 - Unable to Autoload Markdown Class - MGatner - 04-28-2019 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. |