依赖注入,避免在类中实例化对象,使此类高度依赖实例化的类.

Original 2019-04-29 12:03:10 416
abstract:getmdoleobj = $mdole;

依赖注入两种方式,一种普通方法传参。一种构造方法传

include 'mdole.php';

class Coler

{


public $getmdoleobj = '';

public function __construct(Mdole $mdole)

{

$this->getmdoleobj = $mdole;


var_dump($this->getmdoleobj);

}

public function add()

{

include "viiw.php";

}

public function add_do()

{

$name = $_POST['username'];

$password = $_POST['password'];

$this->getmdoleobj->aaa($name,$password);

}

}


$Colerobj = new Coler($mdole);


$r = isset($_GET['r'])?$_GET['r']:'index';


$Colerobj->$r();

?>

2019-04-29_115809.png2019-04-29_115825.png

Correcting teacher:查无此人Correction time:2019-04-30 09:16:11
Teacher's summary:完成的不错。sql语句组装,尽量用单引号,加连接符。不要在双引号里使用变量。继续加油。

Release Notes

Popular Entries