tp5中引入composer中没有的第三方类,将类放入/extend/文件夹中
(1)这里我们创建一个类文件/extend/Person.php
<?php class Person { public $name; public function __construct($name) { $this->name = $name; } public function say() { return $this->name . ' say:hello world!'; } }
在控制器中使用方法:
<?php namespace app\admin\controller; use Person; class Test { public function index() { $person = new Person('ning'); echo $person->say(); } }
(2)这里我们再创建一个类,/extend/com/Machine.php,注意这里的路径于上面的区别
<?php namespace com; /** * */ class Machine { public $name; public function __construct($name) { $this->name = $name; } public function say() { return $this->name . ' say:I am a machine!'; } }
在控制器中的使用方法:
<?php namespace app\admin\controller; use com\Machine; class Test { public function index() { $machine = new Machine('Tom'); echo $machine->say(); } }
声明:
① 凡本网所有原创文章及图片、图表的版权均属微信部落所有,如需转载,需注明“信息来源:微信部落”,并且添加本文地址:http://wxbuluo.com/index/article/28.html
② 凡本网注明“来源:XXX(非微信部落)”的文字及图片内容,均转载自其他媒体,版权归原媒体及作者所有。转载目的在于传递更多的资讯,并不代表本网赞同其观点和对其真实性负责。如有侵权,请联系删除。联系方式:296720094@qq.com
2021 © wxbuluo.com ALL Rights Reserved. 鲁ICP备15005397号-1