Include a file in a controller

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1743
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Include a file in a controller

Post by kinerity » Mon Apr 30, 2018 1:54 am

I have a file named "file.php" in the root of my extension. In my controller, I need to include this file. Is it as simple as include('../file.' . $this->php_ext);? Is that allowed?
Kailey Truscott - Community Team

User avatar
AbaddonOrmuz
Registered User
Posts: 335
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Include a file in a controller

Post by AbaddonOrmuz » Mon Apr 30, 2018 2:06 am

What does that file do? because if that's a class you only need to add the namespace, as you would normally do.
A proudly user of Arch Linux :: /r/sddm_themes

User avatar
3Di
Registered User
Posts: 12753
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Include a file in a controller

Post by 3Di » Mon Apr 30, 2018 2:33 am

Or use it as a service, usually done with helper classes of sort.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1743
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Include a file in a controller

Post by kinerity » Mon Apr 30, 2018 4:37 am

AbaddonOrmuz wrote:
Mon Apr 30, 2018 2:06 am
if that's a class you only need to add the namespace, as you would normally do
I didn't even think about that. Thanks!
Kailey Truscott - Community Team

User avatar
3Di
Registered User
Posts: 12753
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Include a file in a controller

Post by 3Di » Mon Apr 30, 2018 8:41 am

I'd use it for something like constants (which I prefere to put them in the ext.php file), I'd include it as a service if I need to use functions that such "file.php" contains, often used also elsewhere. For just the sake of the inclusion of a small function or two being used only in that controller the best way is to put the function(s) directly in the controller as normal code. As you can see there are different ways to skin a cat - so to speak. :)
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests