Answer the question
In order to leave comments, you need to log in
How to properly use your own class?
I use Yii2 advanced
to unload a bit of code in the Controller.
I want to create a third party class and use it. I made a folder in common
and wrote a class in it, indicated namespace
, and connected it ( use
) in the controller. But it gives an error - this class does not exist!
How to properly implement such a task?
Where to create? And how to connect the class correctly?
Answer the question
In order to leave comments, you need to log in
You can create it anywhere, the main thing is that the namespace takes into account "anywhere")))
for example, we create common/components/MyComponent.php
in it:
<?php
namespace common\components;
class MyComponent
{
public static function fuckMe($name)
{
return 'I fuck, '.$name;
}
}
echo MyComponent::fuckMe('Вася');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question