使用 composer 下载thinkPhp6
切换阿里云镜像:composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
composer create-project topthink/think tp tp6 composer 下载地址
composer create-project topthink/think
redirect('/admin/index')->send();
return View::fetch(“Index/index”,[‘result’=> 111,‘strat’=> 222,‘grades’=> 333]);
在使用函数计算fun上传thinkphp6之后,需要做些小处理,最关键的是函数计算么有写入的权力,只能读。so我们的日志文件或者说runtime文件里的东西就要换个地方存储。但是问题来了,在配置log和cache的时可以直接更改他们的path文件。但是会在试图配置缓存报错也就是下面这个鬼样子
究其原因就是目录的路径是错误的没有写入权限。打印出来是这样子
这是我们的根目录,所以会报错我们要改成挂载的目录,专门放我们的缓存文件也就应该是下面这个样子 DIRECTORY_SEPARATOR 是分隔符,
更改的方法就是找到这个路径 \vendor\topthink\framework\src\think下的App.ph文件更改下路径即可
注意需要按照linux的写法来
DIRECTORY_SEPARATOR . 'mnt' . DIRECTORY_SEPARATOR . 'thinkphp' . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR;
Call to undefined method think\Db::table()
//上述错误是因为我们虽然引入了think\Db这个类,但是没有实例化,所以不能使用Db::table()这种操作
解决方案:需要引入think\Facade\Db这个类才能使用Db::table()。
上传到阿里云函数计算后发现--------本地可以,上面不行,纠结良久,发现是大小写问题,哎。。。。。。。。
更改即可使用
// 开启事务
$this->startTrans();
try {
// 添加商品
$this->allowField(true)->save($data);
// 商品规格
$this->addGoodsSpec($data);
// 商品图片
$this->addGoodsImages($data['images']);
$this->commit();
return true;
} catch (\Exception $e) {
$this->error = $e->getMessage();
$this->rollback();
return false;
}
在thinkphp6中,原先的基类都变没了。其中返回的error错误也“搬家”了
具体位置如下(难受。。。。。。)
$this->validate->getError();
'apart_level' => ['begin', 'error', 'sql', 'yoshop-info'],
转载于-----《数据库中的左连接和右连接的区别》
有两个表a,b
若是使用a表左链b表,会返回a表所有符合查询条件的数据。以及符合条件的b表的部分数据。写法样式如下
首先在你需要调用的model上或者其继承的父类model上写入一个新的方法。根据自己的需要看是一对多,还是一对一,以及上下级的关系。去定义方法。举例假设查询订单表中的一个订单,以及多个发货状态。如下即可
namespace app\back\model\sale;
use app\back\model\AdminUser as AdminUser;
class SaleOrder extends BaseModel {
/**
* 查询数据,关联表查姓名
* @param array $where
* @return bool
*/
public function postSelect($where)
{
$res= $this->alias('o')
->with([
'SaleOrderSend'=> function($query) {
$query->field('order_number,send_count,set_baby,send_state,create_time,send_id')
->with(['SaleSendCar'=>function($query){
$query->field('send_id,driver,car');
}]);
},
'SalePrice'=> function($query) {
$query->field('goods_id,price_fixed');
},
'AdminUser'=> function($query) {
$query->field('admin_id,admin_user_name');
},
'Goods'=> function($query) {
$query->field('goods_id,goods_name');
},
'GoodsType'=> function($query) {
$query->field('goods_type_id,goods_type_name');
},
])
->where($where)//定价表未删除数据
->order('create_time DESC')
->select()
->toArray();
return $res;
}
namespace app\back\model\sale;
use think\Validate;
use app\back\model\BaseModel as Model;
class BaseModel extends Model {
//数据库查询数据
public function AllSelect($where = "",$field = "",$order = "")
{
$res= $this->where($where)
->field($field)
->order($order)
->select()
->toArray();
return $res;
}
//数据库插入数据(返回id)
public function getInsertGetId($data)
{
$res = $this->insertGetId($data);
return $res;
}
//数据库插入数据(不返回id)
public function getInsert($where)
{
$res = $this->insert($where);
return $res;
}
//返回错误信息
public function getError()
{
$validate = new Validate();
$validate->getError();
}
//数据库修改数据
public function getChangeId($where,$data)
{
$res= $this->where($where)->update($data);
return $res;
}
//数据库删除数据
public function getDeleteId($where,$data)
{
$res= $this->where($where)->update($data);
return $res;
}
/**
* 查询该订单下的所有发货信息
* @param string $data
* @return bool
*/
public function SaleOrderSend()
{
return $this->hasMany('SaleOrderSend', 'order_number','order_number');
}
/**
* 查询人的相关信息
* @param string $data
* @return bool
*/
public function AdminUser()
{
return $this->hasOne('app\back\model\AdminUser', 'admin_id','admin_id');
}
/**
* 获取定价(这边的单价)---(定价表)
* @param string $data
* @return bool
*/
public function SalePrice()
{
return $this->hasOne('SalePrice', 'goods_id','goods_id');
}
/**
* 获取物品名称---(物资管理表)
* @param string $data
* @return bool
*/
public function Goods()
{
return $this->hasOne('Goods', 'goods_id','goods_id');
}
/**
* 获取物品类型---(物资类型表)
* @param string $data
* @return bool
*/
public function GoodsType()
{
return $this->hasOne('GoodsType', 'goods_type_id','goods_type_id');
}
}