Blogger Information
Blog 47
fans 0
comment 0
visits 21014
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
composer的常规用法
P粉036614676
Original
487 people have browsed it

上机练习composer常用指令,深刻理解compser应用场景与引用方法

1.不用composer进行包管理

在文件中需要提供路径名,和命名空间

  1. <?php
  2. use inc\myClassOne\student;
  3. use inc\myClassTwo\myClassTwo;
  4. use lib\fun;
  5. require 'inc\myClassOne.php';
  6. require 'inc\myClassTwo.php';
  7. require 'lib\function.php';
  8. $student1 = new student('yk',20,100);
  9. $two = new myClassTwo();
  10. echo fun\fun1(); //注意函数一般在根命名空间,否则需要带上命名空间
  11. echo $student1->getAll();
  12. echo $two->func1();

2.composer进行包管理

2.1函数自动加载

1.创建包管理文件(进入对应的文件夹下面)

  1. composer init

composer.json为配置文件,其中类容可以不要

  1. {
  2. "name": "yk/0823-1",
  3. "autoload": {
  4. "psr-4": {
  5. "Yk\\08231\\": "src/"
  6. }
  7. },
  8. "authors": [
  9. {
  10. "name": "yk",
  11. "email": "yk2199877358@163.com"
  12. }
  13. ],
  14. "require": {}
  15. }

根vendo有关的都是’/‘,其余的都是,’\’

  1. "files": ["lib/function.php","config/connect.php"],

最后require ‘vendor\autoload.php’;进行自动加载

2.2加载类

  1. "classmap": [
  2. "inc/"
  3. ],

类都放在inc文件夹下面
如果加载其他的类文件需要指定道文件

  1. "classmap": [
  2. "inc/myClassOne.php",
  3. "admin/Index.php"
  4. ],

2.3分类管理

“psr-4”: {“phpcn\“:”admin”}:及是映射关系

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post