How to add custom PHP classes for use within application

Permalink
I'm having a hard time finding any documentation on how to create my own classes for use throughout a Concrete5 site in 5.7. For example, I may want to reference this class in controllers, page type controllers, blocks, single pages, etc. In 5.6 I used to either create a Helper or a Model but since these are gone in 5.7 I'm not sure how to go about doing this. My first guess was to simply create my own directory in the application/ directory but I'm not sure this is correct. I'd like to know the right way to go about doing this. I did see some docs on creating my own packages, but it doesn't seem right to have to create a package to hold all my classes. Any insight would be greatly appreciated!

stephendmalloy
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi stephendmalloy,

I believe you can use custom classes the same way in application/src as you would packages/src.

Example:
- application\src\Fruit.php
<?php
namespace Application\Src;
class Fruit
{
    public function getFruit()
    {
        return 'apple';
    }
}

- in a controller
use Application\Src\Fruit;
$fruit = new Fruit();
$fruit->getFruit();

- in a view
$fruit = new Application\Src\Fruit();
echo $fruit->getFruit();
stephendmalloy replied on at Permalink Reply
stephendmalloy
Thanks @MrkDilkington - I'll give this a shot.

Cheers!