Naming Strategy for table and column names (Doctrine ORM) - php

Is it possible to have a naming strategy take care of mapping table and column names in Doctrine ORM?
Right now all names are specified via annotation in the entity classes, e.g.
<?php
namespace App\Entity;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity()
* #ORM\Table(name="role")
*/
class Role
{
/**
* #ORM\Id()
* #ORM\Column(name="id", type="guid")
* #ORM\GeneratedValue(strategy="NONE")
* #var string
*/
private $id;
/**
* #ORM\Column(name="created_at", type="datetime")
* #var \DateTimeImmutable
*/
private $createdAt;
/**
* #ORM\Column(name="created_by", type="string")
* #var string
*/
private $createdBy;
// [..]
}
Table and column names are all snake_case while class and property names are all camelCase.
I've tried to remove table and column name declarations in the entity classes and provided a naming strategy` via configuration, trying to set it in the following two ways.
<?php
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
return [
'doctrine' => [
'connection' => [
// [..]
],
'driver' => [
// [..]
],
'annotation' => [
// [..]
],
'entity_managers' => [
'default' => [
'naming_strategy' => UnderscoreNamingStrategy::class,
],
],
'orm' => [
'naming_strategy' => UnderscoreNamingStrategy::class,
],
],
];
When trying to retrieve an entity, an error is thrown.
Doctrine\DBAL\Exception\InvalidFieldNameException: An exception occurred while executing 'SELECT t0.id AS id_1, t0.createdAt AS createdAt_2, t0.createdBy AS createdBy_3, t0.updatedAt AS updatedAt_4, t0.updatedBy AS updatedBy_5, t0.name AS name_6, t0.desc AS desc_7, t0.isCore AS isCore_8 FROM Role t0':
SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.createdAt' in 'field list' in file C:\project\path\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\AbstractMySQLDriver.php on line 60

After a bit of studying and experimenting, I got the following solution to work in a Zend Expressive application.
Configure naming strategy in doctrine.local.php
<?php
declare(strict_types = 1);
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
return [
'doctrine' => [
'connection' => [
// [..]
],
'driver' => [
// [..]
],
'annotation' => [
// [..]
],
'configuration' => [
'orm_default' => [
'naming_strategy' => UnderscoreNamingStrategy::class,
],
],
],
];
Implement a factory for the naming strategy
<?php
namespace App;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
class NamingStrategyFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new $requestedName();
}
}
Register factory in ConfigProvider.php
<?php
declare(strict_types = 1);
namespace App;
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
class ConfigProvider
{
public function __invoke()
{
return [
'dependencies' => $this->getDependencies(),
];
}
public function getDependencies(): array
{
return [
'invokables' => [
],
'factories' => [
// [..]
UnderscoreNamingStrategy::class => NamingStrategyFactory::class,
],
];
}
}

Related

What causes the 'Unknown format "factory"' error in this Laravel 8 app?

I am working on a Laravel 8 app with users and posts.
The objective is to create a bunch of posts (I already have users).
namespace Database\Factories;
// import Post model
use App\Models\Post;
// import User model
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class PostFactory extends Factory {
/**
* The name of the factory's corresponding model.
*
* #var string
*/
protected $model = Post::class;
/**
* Define the model's default state.
*
* #return array
*/
public function definition() {
return [
'title' => $this->faker->sentence(3),
'description' => $this->faker->text,
'content' => $this->faker->paragraph,
'user_id' => $this->faker->factory(App\Models\User::class),
];
}
}
The problem
I run php artisan tinker then Post::factory()->count(100)->create() in the terminal and I get:
InvalidArgumentException with message 'Unknown format "factory"'
UPDATE
I replace my return statement with:
return [
'title' => $this->faker->sentence(3),
'description' => $this->faker->text,
'content' => $this->faker->paragraph,
'user_id' => User::factory(),
];
I get this in the terminal:
Class 'Database\Factories\UserFactory' not found
Questions:
Where is my mistake?
Does the fact that I get the error Class 'Database\Factories\UserFactory' not found mean that I need to
create a UserFactory factory? Because there isn't one. (I wanted
to create posts, not users).
I don't suppose there is $this->faker->factory(..).
You can do
'user_id' => App\Models\User::factory()->create()->id,
EDIT:
'user_id' => App\Models\User::factory(),
Creating a UserFactory factory and using the below return statement did the trick:
return [
'title' => $this->faker->sentence(3),
'description' => $this->faker->text,
'content' => $this->faker->paragraph,
'user_id' => User::factory(),
];
So, the PostFactory class looks like this:
class PostFactory extends Factory {
/**
* The name of the factory's corresponding model.
*
* #var string
*/
protected $model = Post::class;
/**
* Define the model's default state.
*
* #return array
*/
public function definition() {
return [
'title' => $this->faker->sentence(3),
'description' => $this->faker->text,
'content' => $this->faker->paragraph,
'user_id' => User::factory(),
];
}
}

Laravel Artisan event:generate command throwing a Fatal error

I'm following the official documentation for Laravel 5.7 on the events registration and generation: https://laravel.com/docs/5.7/events#generating-events-and-listeners
I have an EventServiceProvider with the following events defined:
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* #var array
*/
protected $listen = [
'App\Events\FormBeforeCreate' => [
'App\Listeners\WebhookBeforeCreate',
],
'App\Events\FormAfterCreate' => [
'App\Listeners\NotifyAfterCreate',
'App\Listeners\WebhookAfterCreate',
],
'App\Events\FormBeforeUpdate' => [
'App\Listeners\WebhookBeforeUpdate',
],
'App\Events\FormAfterUpdate' => [
'App\Listeners\NotifyAfterUpdate',
'App\Listeners\WebhookAfterUpdate',
],
'App\Events\FormBeforeDelete' => [
'App\Listeners\WebhookBeforeDelete',
],
'App\Events\FormAfterDelete' => [
'App\Listeners\NotifyAfterDelete',
'App\Listeners\WebhookAfterDelete',
],
'App\Events\FormBeforeSave' => [
'App\Listeners\WebhookBeforeSave',
],
'App\Events\FormAfterSave' => [
'App\Listeners\NotifyAfterSave',
'App\Listeners\WebhookAfterSave',
],
];
/**
* The subscriber classes to register.
*
* #var array
*/
protected $subscribe = [
'App\Listeners\UserEventSubscriber',
];
/**
* Register any other events for your application.
*
* #return void
*/
public function boot()
{
parent::boot();
}
}
The error:
When I run the command php artisan event:generate I get the following error:
PHP Fatal error: Call to a member function listens() on null in /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/EventGenerateCommand.php on line 35
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function listens() on null
According to the doc, it should do this:
This command will generate any events or listeners that are listed in
your EventServiceProvider. Events and listeners that already exist
will be left untouched
I don't understant what I've missed since I didn't find any similar error by searching the web
This is the line that is returning null:
$providers = $this->laravel->getProviders(EventServiceProvider::class);
therefore, there are some problems with your EventServiceProvider... please, try using this:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* #var array
*/
protected $listen = [
'App\Events\FormBeforeCreate' => [
'App\Listeners\WebhookBeforeCreate',
],
'App\Events\FormAfterCreate' => [
'App\Listeners\NotifyAfterCreate',
'App\Listeners\WebhookAfterCreate',
],
'App\Events\FormBeforeUpdate' => [
'App\Listeners\WebhookBeforeUpdate',
],
'App\Events\FormAfterUpdate' => [
'App\Listeners\NotifyAfterUpdate',
'App\Listeners\WebhookAfterUpdate',
],
'App\Events\FormBeforeDelete' => [
'App\Listeners\WebhookBeforeDelete',
],
'App\Events\FormAfterDelete' => [
'App\Listeners\NotifyAfterDelete',
'App\Listeners\WebhookAfterDelete',
],
'App\Events\FormBeforeSave' => [
'App\Listeners\WebhookBeforeSave',
],
'App\Events\FormAfterSave' => [
'App\Listeners\NotifyAfterSave',
'App\Listeners\WebhookAfterSave',
],
];
/**
* Register any events for your application.
*
* #return void
*/
public function boot()
{
parent::boot();
//
}
}
My bad, it seems like I was really tired yesterday night, Our project runs on Docker, I was running the command outside of the docker instead of inside.
I have no idea why it showed this bug in particular but once I ran the command in the docker all files generated correctly.

Integrate doctrine in slim 4 using php-di

Trying to use doctrine with slim 4 and php-di I don't get it running with autowire.
Following my setup:
index.php
$definitions = [
'settings' => [
'doctrine' => [
'dev_mode' => true,
'cache_dir' => __DIR__.'/../var/cache/doctrine',
'metadata_dirs' => [__DIR__.'/../src/Domain/'],
'connection' => [
'driver' => 'pdo_mysql',
'host' => 'webdb',
'port' => 3306,
'dbname' => 'db',
'user' => 'user',
'password' => 'pass',
]
]
],
EntityManagerInterface::class => function (ContainerInterface $c): EntityManager {
$doctrineSettings = $c->get('settings')['doctrine'];
$config = Setup::createAnnotationMetadataConfiguration(
$doctrineSettings['metadata_dirs'],
$doctrineSettings['dev_mode']
);
$config->setMetadataDriverImpl(
new AnnotationDriver(
new AnnotationReader,
$doctrineSettings['metadata_dirs']
)
);
$config->setMetadataCacheImpl(
new FilesystemCache($doctrineSettings['cache_dir'])
);
return EntityManager::create($doctrineSettings['connection'], $config);
},
UserRepositoryInterface::class => get(UserRepository::class)
then my repository:
class UserRepository extends \Doctrine\ORM\EntityRepository implements UserRepositoryInterface {
public function get($id){
$user = $this->_em->find($id);
...
}
}
Currently I get the follwoing error message:
"Doctrine\ORM\Mapping\ClassMetadata" cannot be resolved: Parameter $entityName of __construct() has no
value defined or guessable
Full definition:
Object (
class = Doctrine\ORM\Mapping\ClassMetadata
lazy = false
...
can somebody tell me how to solve that issue respectively is there any other maybe cleaner/easier way to integrate doctrine using php-di?
Update
Referring to the hint that ClassMetadata can't be autowired I changed the structure as follows:
index.php
$definitions = [
EntityManager::class => DI\factory([EntityManager::class, 'create'])
->parameter('connection', DI\get('db.params'))
->parameter('config', DI\get('doctrine.config')),
'db.params' => [
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => '',
'dbname' => 'foo',
],
'doctrine.config' => Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src/core/models/User"), true),
...
userservice/core/models/User.php:
namespace userservice\core\models;
use userservice\core\exceptions\ValidationException;
use \DateTime;
use ORM\Entity;
/**
* #Entity(repositoryClass="userservice\infrastructure\repositories\UserRepository")
*/
class User extends Model{
/**
* #Column(type="string", length="50")
* #var string
*/
private $name;
...
And the userservice/infrastructure/UserRepository.php:
namespace userservice\infrastructure\repositories;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\ORMInvalidArgumentException;
use userservice\core\models\User;
use userservice\core\repositories\UserRepositoryInterface;
use userservice\infrastructure\repositories\Repository;
class UserRepository extends Repository implements UserRepositoryInterface {
private $_repository;
/**
*
* #param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager) {
parent::__construct($entityManager);
$this->_repository = $entityManager->getRepository('User'); // OR $this->entityManager->find('User', 1);
}
Now I'm getting the following error in UserRepository construct (getRepository):
Uncaught Doctrine\Persistence\Mapping\MappingException: Class 'User' does not exist in C:\projects\microservices\user-service\vendor\doctrine\persistence\lib\Doctrine\Persistence\Mapping\MappingException.php
How can I get doctrine find the entities?

ZF2 injecting InputFilter into Fieldset not working automatically

I'm building a small application with ZF2 and Doctrine2. Setting it up in such a way as to have a lot of reusable code and technique. However, getting stumped by the fact that my InputFilter is not automatically injected into the Fieldset that it should get associated to.
I've confirmed that the Form that uses the Fieldset works (without the InputFilter). The InputFilter is also visible as present during debugging.
The question then, what am I doing wrong and how to fix having a separate InputFilter, coupled to a Fieldset in ZF2?
Sidenotes:
1 - I am aware that by using the InputFilterInterface I could have the InputFilter inside of the Fieldset class with the getInputFilterSpecification() function. However, as I'm trying to keep it DRY and reusable, it wouldn't do to have to copy it if I were to create an API that needs to use the Entity and InputFilter, but can only have the latter coupled with a Fieldset.
2 - A lot of Abstract classes are used, where used I'll indicate in the snippets what they have that's relevant
3 - The problem line is in CustomerFieldsetFactory.php
=========================================================================
Entity: Customer.php
/**
* Class Customer
* #package Customer\Entity
*
* #ORM\Entity
* #ORM\Table(name="customers")
*/
class Customer extends AbstractEntity //Contains $id
{
/**
* #var string
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
protected $name;
}
Form: CustomerForm.php
class CustomerForm extends AbstractForm
{
public function __construct($name = null, array $options)
{
parent::__construct($name, $options); // Adds CSRF
}
public function init()
{
$this->add([
'name' => 'customer',
'type' => CustomerFieldset::class,
'options' => [
'use_as_base_fieldset' => true,
],
]);
//Call parent initializer. Check in parent what it does.
parent::init(); //Adds submit button if not in form
}
}
Fieldset: CustomerFieldset.php
class CustomerFieldset extends AbstractFieldset //Contains EntityManager property and constructor requirement (as we're managing Doctrine Entities here)
{
public function init()
{
$this->add([ //For now id field is here, until InputFilter injection works
'name' => 'id',
'type' => Hidden::class,
'attributes' => [
'id' => 'entityId',
],
]);
$this->add([
'name' => 'name',
'type' => Text::class,
'options' => [
'label' => _('Name'),
],
]);
}
}
InputFilter: CustomerInputFilter.php
class CustomerInputFilter extends AbstractInputFilter
{
public function init()
{
parent::init();
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class],
['name' => StripTags::class],
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 3,
'max' => 255,
],
],
],
]);
}
}
Above the classes. Below the Factories
FormFactory: CustomerFormFactory.php
class CustomerFormFactory implements FactoryInterface, MutableCreationOptionsInterface
{
/**
* #var array
*/
protected $options;
/**
* #param array $options
*/
public function setCreationOptions(array $options)
{
//Arguments checking removed
$this->options = $options;
}
/**
* #param ServiceLocatorInterface|ControllerManager $serviceLocator
* #return CustomerForm
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$serviceManager = $serviceLocator->getServiceLocator();
$form = new CustomerForm($this->options['name'], $this->options['options']);
$form->setTranslator($serviceManager->get('translator'));
return $form;
}
}
FieldsetFactory: CustomerFieldsetFactory.php
class CustomerFieldsetFactory implements FactoryInterface, MutableCreationOptionsInterface
{
/**
* #var string
*/
protected $name;
public function setCreationOptions(array $options)
{
//Argument checking removed
$this->name = $options['name'];
}
public function createService(ServiceLocatorInterface $serviceLocator)
{
$serviceManager = $serviceLocator->getServiceLocator();
$fieldset = new CustomerFieldset($serviceManager->get('Doctrine\ORM\EntityManager'), $this->name);
$fieldset->setHydrator(new DoctrineObject($serviceManager->get('doctrine.entitymanager.orm_default'), false));
$fieldset->setObject(new Customer());
$fieldset->setInputFilter($serviceManager->get('InputFilterManager')->get(CustomerInputFilter::class));
//RIGHT HERE! THE LINE ABOVE IS THE ONE THAT DOES NOT WORK!!!
return $fieldset;
}
}
InputFilterFactory: CustomerInputFilterFactory.php
class CustomerInputFilterFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$repository = $serviceLocator->getServiceLocator()
->get('Doctrine\ORM\EntityManager')
->getRepository(Customer::class);
return new CustomerInputFilter($repository);
}
}
Config: module.config.php
'controllers' => [
'factories' => [
CustomerController::class => CustomerControllerFactory::class,
],
],
'form_elements' => [
'factories' => [
CustomerForm::class => CustomerFormFactory::class,
CustomerFieldset::class => CustomerFieldsetFactory::class,
],
],
'input_filters' => [
'factories' => [
CustomerInputFilter::class => CustomerInputFilterFactory::class,
],
],
'service_manager' => [
'invokables' => [
CustomerControllerService::class => CustomerControllerService::class,
],
],
I am hoping one of you can help me out here.
EDIT: Update with actual error
The following line in the CustomerFieldset.php (above) triggers the error.
$fieldset->setInputFilter($serviceManager->get('InputFilterManager')->get(CustomerInputFilter::class));
The error:
Fatal error: Call to undefined method Customer\Fieldset\CustomerFieldset::setInputFilter() in D:\htdocs\server-manager\module\Customer\src\Customer\Factory\CustomerFieldsetFactory.php on line 57
As seen in the above snippet, the InputFilter (and it's Factory) are known the the InputFilterManager.
The error states it does not know the getInputFilter() function on the Fieldset. Which is correct in a way, it doesn't exist. The question then is, how to have the function exist so that injecting the InputFilter will work, or how to bind this InputFilter to the Fieldset?
EDIT 2: Update based on Wilt's answer
Added use InputFilterAwareTrait to Abstract class AbstractInputFilter to create following (from answer):
use Zend\InputFilter\InputFilterAwareTrait;
abstract class AbstractFieldset extends Fieldset
{
use InputFilterAwareTrait;
// ... Other code
}
Turns out that I had another mistake in the (original) code above as well:
In file module.config.php the input_filters should've been input_filter_specs. This was (after using the Trait) a Invalid Factory registered error (titled ServiceNotCreatedException).
The following might be of use to someone, the Factory to create a Fieldset with Hydrator, Object and Inputfilter has the following createService() function:
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** #var ServiceLocator $serviceManager */
$serviceManager = $serviceLocator->getServiceLocator();
/** #var CustomerRepository $customerRepository */
$customerRepository = $serviceManager->get('Doctrine\ORM\EntityManager')->getRepository(Customer::class);
$fieldset = new CustomerFieldset($serviceManager->get('Doctrine\ORM\EntityManager'), $this->name);
$fieldset->setHydrator(new DoctrineObject($serviceManager->get('doctrine.entitymanager.orm_default'), false));
$fieldset->setObject(new Customer());
$fieldset->setInputFilter($serviceManager->get('InputFilterManager')->get(CustomerInputFilter::class, $customerRepository));
return $fieldset;
}
There is lots of information added to your question. I'd suggest you try to narrow down your question in the future. Read more on the guidelines for a good question here: How to create a Minimal, Complete, and Verifiable example.
Zend framework provides a InputFilterAwareTrait with both the setInputFilter and getInputFilter methods. You can easily implement/use this trait inside your CustomerFieldset class:
use Zend\InputFilter\InputFilterAwareTrait;
class CustomerFieldset extends AbstractFieldset
{
use InputFilterAwareTrait;
//...remaining code
}
In case you want the inputfilter in all classes that extend your abstract AbstractFieldset class you could also decide to add the trait there:
use Zend\InputFilter\InputFilterAwareTrait;
class AbstractFieldset
{
use InputFilterAwareTrait;
//...remaining code
}
See the following question: How to validate nested fieldsets. Fieldsets don't contain InputFilters but you should extend your base InputFilter of your form.
Create an InputFilter for each Fieldset and add them, with the same name as your fieldset, to your InputFilter of your form. As seen within the answer of the other question I linked.
If you don't want to do this you might consider working with InputSpecification.

how to call background function from web controller in yii2

I have a controller function that save some file in DB and then create personal PDF file for every record in DB and email it to him . The problem is that it take to much time. Can I call console controller from the web controller function and pass the id to the console function? Or there is a better or other method to do this?
I don't think calling console command from web controller will help too much.
But for this purpose you can use for example this extension.
Usage:
Imported class:
use vova07\console\ConsoleRunner;
$cr = new ConsoleRunner(['file' => '#my/path/to/yii']);
$cr->run('controller/action param1 param2 ...');
Application component:
// config.php
...
components [
'consoleRunner' => [
'class' => 'vova07\console\ConsoleRunner',
'file' => '#my/path/to/yii' // or an absolute path to console file
]
]
...
// some-file.php
Yii::$app->consoleRunner->run('controller/action param1 param2 ...');
But I recommend to use work queues for that like RabbitMQ or Beanstalkd, these are more suitable for your task.
I think is better you use a proper class with proper function/metohd , share this in common area and invoke the function in the different controllers
common model
namespace common\models;
use Yii;
/**
* This is the model class for table "c2_common_user_param".
*
* #property integer $id
* #property integer $user_id
* #property string $land_scope_code
* #property string $init_lat
* #property string $init_lng
* #property integer $init_zoom
* #property string $google_maps_api_key
*
* #property DfenxUser $user
*/
class UserParam extends \yii\db\ActiveRecord
{
/**
* #inheritdoc
*/
public static function tableName()
{
return 'c2_common_user_param';
}
/**
* #inheritdoc
*/
public function rules()
{
return [
[['user_id'], 'required'],
[['user_id', 'init_zoom'], 'integer'],
[['init_lat', 'init_lng'], 'number'],
[['land_scope_code'], 'string', 'max' => 4],
[['google_maps_api_key'], 'string', 'max' => 255]
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'user_id' => Yii::t('app', 'User ID'),
'land_scope_code' => Yii::t('app', 'Land Scope Code'),
'init_lat' => Yii::t('app', 'Init Lat'),
'init_lng' => Yii::t('app', 'Init Lng'),
'init_zoom' => Yii::t('app', 'Init Zoom'),
'google_maps_api_key' => Yii::t('app', 'Google Maps Api Key'),
];
}
}
backend controller
<?php
namespace backend\controllers;
use Yii;
use common\models\UserParam;
use common\models\UserParamSearch;
use common\models\User;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* UserParamController implements the CRUD actions for UserParam model.
*/
class UserParamController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all UserParam models.
* #return mixed
*/
public function actionIndex()
{
$searchModel = new UserParamSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}
frontend controller
<?php
namespace frontend\controllers;
use Yii;
use common\models\UserParam;
use common\models\UserParamSearch;
use common\models\User;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* UserParamController implements the CRUD actions for UserParam model.
*/
class UserParamController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all UserParam models.
* #return mixed
*/
public function actionIndex()
{
$searchModel = new UserParamSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}

Categories