What is the best way to share custom PHP functions between blocks?
Permalink 1 user found helpful
Hi everyone,
I'm using concrete5.7.5.7
I'm writing different block types, and some PHP functions are the same between these block types.
What is the best way to share custom PHP functions between blocks?
I'm using concrete5.7.5.7
I'm writing different block types, and some PHP functions are the same between these block types.
What is the best way to share custom PHP functions between blocks?
Thank you for your answer.
If I have no package and I use directly the application directory, is it correct to do :
In my block view.php:
and in the file containg the shared class
saving my class in:
application/src/Myclass.php
If I have no package and I use directly the application directory, is it correct to do :
In my block view.php:
and in the file containg the shared class
<?php namespace Application\Src; Class Myclass { public function doSomething() {} }
saving my class in:
application/src/Myclass.php
I never use the applicaton map myself, but it looks like that should work
You might however want to insert an extra map into scr to avoid conflicts.
Like application/src/yourname/Myclass.php
You might however want to insert an extra map into scr to avoid conflicts.
Like application/src/yourname/Myclass.php
If I understand well the directory structure, everything under application/ is specific to a single website and everything under concrete/ is related to the core.
What kind of conflicts do you think of?
What kind of conflicts do you think of?
It might override files in /concrete/src if it had the same name by coincidence
However, without testing this, I can't say 100% sure it would. It's just a precaution and good habit.
However, without testing this, I can't say 100% sure it would. It's just a precaution and good habit.
I understand and I think it's indeed a good precaution.
Thank you.
Thank you.
use Concrete\Package\YourPackage\Src\Yourclass.php
Yourclass::doSomething();
namespace your class:
save your class to:
packages/your_package/src/Yourclass.php
(mind the capital)