自動初始化插件文件
dayrui/App/插件目錄/Config/Auto.php
以QueryList類爲例,如何自動加載進來呢?
1、通過QueryList官網的Composer命令下載源碼到任意目錄
2、將下載下來的vendor目錄複製到插件的目錄:
dayrui/App/插件目錄Test/vendor
3、打開dayrui/App/插件目錄Test/Config/Auto.php,加入代碼
<?php // 在這裏引入Composer的自動加載文件 require APPPATH.'vendor/autoload.php';
3、新建test控制器來使用QueryList類,
dayrui/App/Test/Controllers/Test.php
控制器內容如下:
<?php namespace Phpcmf\Controllers; use QL\QueryList; class Test extends \Phpcmf\Common { public function index() { //採集某頁面所有的圖片 $data = QueryList::get('https://www.xunruicms.com')->find('img')->attrs('src'); //打印結果 print_r($data->all()); } }
這個例子代碼是QueryList官方示例代碼
4、運行程序地址:
http://www.xxxx.com/index.php?s=test&c=test&m=index