父类调用子类的常量 lumen查询数据库方式
我要在一个基类里面实例化所有的model 要根据集成的对象定义的model实例化
BaseRepository.php
<?php namespace App\Repository; class BaseRepository
{ //获取到model的对象 类似于再仓储里面直接 User::get()
public function query()
{
$model = static::MODEL; //通过这个可以调用到子类定义的MODEL常量
return new $model();
} }
UserRepository.php
<?php namespace App\Repository; //仓储 用于连接service和model
use App\Model\User;
use Illuminate\Support\Facades\DB; class UserRepository extends BaseRepository
{
const MODEL = User::class; public function getUserList()
{ $res = (new User())->first(); //new对象后查询
$res = User::first(); //直接静态调用查询 $query = $this->query(); //调用基类返回对象后查询
return $res;
}
}
父类调用子类的常量 lumen查询数据库方式的更多相关文章
- PHP面向对象-看父类调用子类方法
大部分面向对象编程语言中,父类是不允许调用子类的方法的,但是PHP中可以 1.父类调用子类方法示例 class A { public function testa() { $this->test ...
- php 父类调用子类方法和成员
在C和C++里,父类都不允许调用子类的方法,但在php里可以.下面是一个调用的例子: <?php abstract class Animal { protected $name; public ...
- php面向对象编程 父类调用子类编程
使用父类调用子类的实现代码
- 多态&&父类调用子类特有的方法
/* 多态 1.没有继承就没有多态 2.代码的体现:父类类型的指针指向子类对象 3.好处:如果函数\方法参数使用的是父类对象,可以传入父类.子类对象 4.局限性: 1>父类类型的变量,不能直接调 ...
- java 多态 ---父类调用子类方法
package test1;//多态的体现import javax.print.attribute.standard.RequestingUserName;import java.util.Scann ...
- java反射与多态(父类调用子类)的代码演示
package Test0817; import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method ...
- Python父类调用子类
首先说明,上面的标题其实是不正确的,Python是一门解释型.动态数据类型的高级语言,运行时,动态判断调用对象,其实还是子类自己在调用自己的方法或属性. 举个例子(copy过来的):SocketSer ...
- python父类调用子类了解一下
class B(): def __init__(self): pass def start(self): print(self.parse()) class A(B): def __init__(se ...
- Java 中父类怎么调用子类的方法?
父类能调用子类的方法吗? 答:能. 怎么做? ● 把子类传递到父类的有参构造中,然后调用. ● 使用反射的方式调用,你使用了反射还有谁不能调用的?! ● 父类调用子类的静态方法. 案例展示: pack ...
随机推荐
- 算法习题---5.3字典(Uva10815)
一:题目 给出一段英文,里面包含一些单词,空格和标点,单词不区分大小写,默认都为小写.按照字典序输出这些单词(这些单词不能有重复,字母全部变成小写) (一)样例输入 Adventures in Dis ...
- linux记录-安装zabbix监控系统
1. 安装依赖yum -y install libcurl-devel libxml2-devel net-snmp net-snmp-devel2. 安装 nginxyum -y install n ...
- springboot 项目基本目录包结构
1.基本目录结构 controller service impl mapper utils domain config interceoter(拦截器) dto
- tensor&ndarray&int、float
(1)如果tensor只有一个元素,然后转换成int或者float类型的时候直接用int()或者float()就可以了: (2)如果tensor含有多个元素,转换成ndarray时就要用x.detac ...
- LeetCode_203. Remove Linked List Elements
203. Remove Linked List Elements Easy Remove all elements from a linked list of integers that have v ...
- 【物联网】传感器+wifi传输+回复+显示
https://www.jianshu.com/p/cb0274d612b5 https://timgsa.baidu.com/timg?image&quality=80&size=b ...
- prometheus数据格式
注意区分以下两种“数据格式”: 1.自定义exporter的时候所需要遵循的给prometheus提供数据的数据格式: https://yunlzheng.gitbook.io/prometheus- ...
- macos的iptables功能是pfctl
pfctl https://www.kokaruk.com/macos-pf-firewall/ https://blog.csdn.net/yjy1304/article/details/90762 ...
- 【计算机视觉】目标检测之ECCV2016 - SSD Single Shot MultiBox Detector
本文转载自: http://www.cnblogs.com/lillylin/p/6207292.html SSD论文阅读(Wei Liu--[ECCV2016]SSD Single Shot Mul ...
- Qt5.编译错误.error: C2338: The slot requires more arguments than the signal provides.
1.Qt563x86vs2015,遇到如下 编译错误: error: C2338: The slot requires more arguments than the signal provides. ...