php - 在 php 中真正需要做什么

标签 php require

我是 PHP 新手,在使用 require 时遇到问题。

Folder structure

  • 'Config.php' 在父文件夹中
  • 模型包含测试,其中 'LaptopModel.php' 是。
  • Controller 包含文件“LaptopController.php”

在 Config.php 中:

<?php
$host = "localhost";
$username = "admin";

在 LaptopModel.php 中:

<?php
require '../../Config.php';

在 LaptopController.php 中:

<?php
require '../Model/test/LaptopModel.php';

问题是当服务器处理这个文件时,LaptopController.php 中的代码到底是什么? 我以两种方式考虑这一点,这两种方式是否会导致错误。

<?php
require '../../Config.php';// get the original code from required file
//this cause an error, because from LaptopController.php
//the link to Config.php must be '../Config.php'

或者它将是:

<?php
$host = "localhost";
$username = "admin";
//get what was required from Laptopmodel.php file, not the original code

最佳答案

相对于你的问题部分,Require 真正做的很简单...... 如果文件丢失或找不到它会产生一个 fatal error 并停止脚本的执行

来源:http://www.w3schools.com/php/php_includes.asp

关于php - 在 php 中真正需要做什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34671230/

相关文章:

javascript - 在 React JS 中需要带有变量的文件

node.js - 如何处理 Node.js 中的循环依赖

php - Mysql Select random rows to n次

mysql - 使用bundler来要求dll和gem

javascript - 使用 PHP/JavaScript/AJAX 添加行到数据库

php - 拉维尔 5 : Using SHA1 instead of Bcrypt

Node.js:需要本地人

ruby - Gem 不加载 config.ru

php - PHP 中的 ArrayAccess——通过引用分配给偏移量

PHP 分页 最后 id 记录