简体   繁体   English

Laravel扩展BaseController和Vendor控制器

[英]Laravel Extend BaseController and Vendor controller

I'm using Jacopo Authentication package in one of my sites, I'm extending it to add some methods and do stuff after I call its methods, I'm extending it like this: 我在我的一个站点中使用Jacopo Authentication软件包 ,我将其扩展为添加一些方法并在调用其方法后做一些事情,我将其扩展为:

<?php
use Jacopo\Authentication\Controllers\UserController as JacopoUserController;
class UserController extends JacopoUserController{
...
}

Now, the problem is that I need to use some methods from my BaseController, whats the best way to be able to use BaseController here? 现在,问题是我需要使用BaseController中的某些方法,在这里能够使用BaseController的最佳方法是什么? Should I just instantiate it? 我应该实例化它吗? Maybe move as much logic as I can to a Model or Helper and duplicate a little code? 也许将尽可能多的逻辑转移到“模型”或“帮助器”并复制一些代码? Is there anything like this? 有没有这样的东西?

class UserController extends JacopoUserController extends BaseController{

Thank you in advance. 先感谢您。

You can extend only one class in PHP. 您只能在PHP中扩展一个类。 However you could create trait and put there functionality from Basecontroller and to use this functionality simple add use Traitname; 但是,您可以创建特征并从Basecontroller那里放置功能,并且要使用此功能, Basecontroller简单地添加use Traitname; to class that needs that functionality 分类需要该功能的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM