Codeigniter 3 - Third_party and controllers / loading ressources
<p>I'd like to use the controllers from the <code>/third_party/myapp/controllers</code> folder without having to move them to the <code>/application/controllers</code> one</p>
<p>It doesn't seem possible (at least not without hacking the core). Though the question concerns loading model, limitations are mentioned <a href="https://stackoverflow.com/questions/11873275/using-codeigniter-tank-auth-as-a-package">here</a></p>
<p>I don't feel like using HMVC - as stated in the solution proposed there, cause I don't need any other functionality than avoiding to multiply file transfer in CI base folders (i don't really need the 'hierarchical' part of it)</p>
<p>But I don't really get it... if one declares its third_party app, CI will load resources from those folders (as stated by <a href="https://www.codeigniter.com/user_guide/libraries/loader.html#application-packages" rel="nofollow noreferrer">the doc</a>)</p>
<blockquote>
<p>config/</p>
<p>helpers/</p>
<p>language/</p>
<p>libraries/</p>
<p>models/</p>
</blockquote>
<p><strong>[metaphysical]</strong> Why wouldn't it be possible to simply load controllers as well ?</p>
<p><strong>[pragmatic]</strong> is it a good idea to try to hack the core system or should I stay on the &quot;HMVC or do copy your files&quot; choice ?</p>
<p><strong>[optimistic]</strong> do someone have a solution ?</p>
<h2>EDIT</h2>
<p>While looking further to trajchevska tip in another installation of CI, I tried to implement DFriend example of spl_register. I read several times the manual and this <a href="https://stackoverflow.com/questions/7651509/someone-explain-spl-autoload-autoload-and-spl-autoload-register">answer</a> as well :
So far I understood that spl_autoload_register is triggered when a class is called, which allows to skip their manual loading</p>
<p>So I've tried simply adding the <code>spl_autoload_register</code> at the end of the config file in <code>application/config/config.php</code>, expecting it to print <em>Auto load ClassName</em> when a first class is called - a bit naïve, I know.</p>
<p>but from what I understood (thanks to DFriend), this spl_autoload_register would NOT work with controllers, as CI will always check if the file exists (in its own path) before trying to declare the controller.</p>
<p><em>It seems on the other hand that it could work with other classes (core, model ... see DFriend answer below)</em></p>
<h1>Conclusion</h1>
<p>So, after a few hairs pulled out of my head, I decided to try the HMVC extension for CI - <a href="https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/overview" rel="nofollow noreferrer">MX from WireDesign</a>. It solved my problem of loading any resources from different folder, along with bringing a brand new scope of shared classes and their attached issues (what is available where ?).</p>
<p>As it's the beginning the project I had the opportunity to switch to the &quot;hierarchical&quot; side, otherwise I'd followed Dfriend's advice of</p>
<blockquote>
<p>going with the flow and putting controllers for third-party packages
where CI expects them to be</p>
</blockquote>