Laravel Voyager add additional methods to a BREAD controller - php

I created a new database through Voyager admin and created BREAD for that table. Now I need to add additional methods to that controller.
I tried to create a custom controller by following this. But the default actions (CRUD) of the controllers are gone.
Without disturbing the existing functionalities of the BREAD I need to add a few more methods in that controller. Is this possible?

I believe you missed to extend voyager's default BREAD controller. for example let say we want to extend a Controller for our Product Model. so we make a ProductController like :
<?php
namespace App\Http\Controllers;
class ProductController extends TCG\Voyager\Http\Controllers\VoyagerBaseController{
//add more functions
}
good luck

Related

How to add a View class for a plugin in cakephp 3?

As the heading to this question states how does one go about adding/integration a View class to a plugin in Cakephp 3?
There is the AppView class for the application but when baking a plugin no View class is included.
There is no View class baked into plugin, because by default plugins are using View class from main application.
If you need to do some specific view-rendering logic in your plugin, you can create eg. YourPluginDir/src/View/CustomView.php and do your things there. You need also to tell your controller to use this View class:
$this->viewBuilder()->setClassName('YourPlugin.Custom');
More info about custom View classes can be found in docs:
Creating your own view classes in CakePHP

How to use `postUpdate` in CRUD controllers?

I've installed SonataAdminBundle and created custom CRUD controller for one entity. I want to perform some action after entity updated. How can I achieve this using CRUD controller's? I've noticed, that Admin* classes have preUpdate and postUpdate methods for such purpose, I could use them, but I guess, that logic should be placed in controllers.
The easiest way I see it's rewriting editAction (override this method in my controller, copy/paste code from base CRUDController and add calling own postUpdate), but copy/paste it's bad:) Maybe I missed some way?
If you review code written in sonata admin's editAction() in CRUDController you can see its calling admin's update() method.
$object = $this->admin->update($object);
you can review update() method in sonata base admin class before calling model manager to persist object it has a preUpdate() call and same case for postUpdate() after calling model manager.
That means the one you are trying to implement pre or post actions for your entity you have to write your own logic but the question is why you want to redo or rewrite any available action ? you can use already provided pre or post hooks.

How to add models in controller in my own Modules?(Yii2)

I use Yii2 for create an web application. In this application i need to create my own Module. I create Home module, and put there Module.php class, and 3 folders(MVC). After i configure the application(main.php) and "add" my module.
In controller i load view and test it in browser. Its works fine without using models. When i want to add model in controller, it show some error. Please help me to customize my controller for use model.
I tried this path in controller for model:
app\modules\home\model\MyOwnSuperModel
but it doesnt work, have any ideas?
Thanks.
P.S. Model i create with generator Gii.

Can you use form validation callback in codeigniter when the function is located on different controller?

Let us say I have 2 controllers, the Users controller and the Admin controller. In Users, I am validating a form to check if the user credentials is correct so I created the callback_confirmUser function in form_validation.php and put the confirmUser function in the Users Controller. How can I use this function inside the Admin controller for form validation too?
The only way to do that is to override from the Admin controller. But I don't think that that's the way to go.
Why don't you create a library for that? It's also possible to extend the CI form validation library in case you miss functionality.
See also: http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html and http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
Good luck!
Edit: it's also possible to use a core controller. You create in the 'core' folder the controller 'MY_Controller.php' that extends the CI_Controller. Instead of extending your controllers from CI_Controller, you extend from MY_Controller. It's than possible to put your validate function in MY_Controller and use it in both admin and user controller.

Load frontend model class in admin controller in Opencart

I want to load a model class which is in frontend(catalog/model/account/address) in admin controller. I can do it by copying that model to admin's model folder but I want to do it without copying model class.
Is there is any way to do it? or I have to modify the loader class. Any suggestion?
Thanks in advance..
The address methods are available in the catalog side via the admin/model/sale/customer.php file in the admin. Simply use that instead
$this->load->model('sale/customer');
$addresses = $this->model_sale_customer->getAddresses(12345);

Categories