php页面修改器,读取器/修改器
名字 命名 get(Price)Attr($price,$data)
Index文件<?php
namespace?app\index\controller;
use?\app\index\model\Shop_name;
class?Index
{
public?function?index()
{
$shop?=?Shop_name::get(2);
return?$shop->price;
}
}
model/Shopname<?php
namespace?app\index\model;
use?think\Model;
class?Shop_name?extends?Model
{
protected?function?getPriceAttr($price,$data)
{
return?$data['name'].$price;
}
}
只需要改價格
修改器
Index<?php
namespace?app\index\controller;
use?\app\index\model\Shop_name;
class?Index
{
public?function?index()
{
$shop?=?new?Shop_name;
$shop->name?='php';
$shop->price='12';
$shop->type='php';
if?($shop->save()){
return?'保存成功';
}else{
return?$shop->getError();
}
}
model/Shopname<?php
namespace?app\index\model;
use?think\Model;
class?Shop_name?extends?Model
{
protected?function?setPriceAttr($price)
{
return?$price;
}
}
只需要改價格
總結
以上是生活随笔為你收集整理的php页面修改器,读取器/修改器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 机数,PHP实现自动刷数和“灌水
- 下一篇: 在php中如何便利字符串,php字符串可