require

PHP - Read number of dirs and then require for each a specified file name

笑着哭i 提交于 2019-12-13 03:53:48
问题 I want to make a little script but I'm rather n00b in php so please help me if you can :) What I want the script to do is: I have "index.php". I want "index.php" to read the sub-directories from a known folder, let's say "templates/" Each sub-directory will contain a file called "content.html". The index will then load the "content.html" with the require() function for each of the existing sub-directories. Thank you very much for your help! 回答1: The RecursiveDirectoryIterator runs through the

Platform issue in require('os')

时光毁灭记忆、已成空白 提交于 2019-12-13 03:36:43
问题 I have created an Ionic 3(A5) app. I am running this as node-webkit (NW.JS) app on Mac. If I write inside index.html script tag and check, require('os') platform returns ' darwin ' and require('fs') returns full set of object correctly. But if I write same script inside a .ts file - require('os') platform returns ' browser ' and require('fs') returns empty object. I am using @types/node in devDependencies. Code inside index.html - var os = require('os'); var fs = require('fs'); console.log(

how to pass variables between 2 php pages when the latter called with require()

匆匆过客 提交于 2019-12-13 03:18:00
问题 I am a PHP newbie, and I have this question: say I have: a.php: $a = 'foo' ; $b = 'baz' ; require ('b.php') ; How do I pass variables $a and $b to b.php ? How do I use these variables in b.php ? thanks a lot !! 回答1: Just make sure you call require() after setting the variables, and they should be available in b.php. a.php: $a = 'foo'; $b = 'baz'; require('b.php'); b.php: echo 'a: '. $a; echo 'b: '. $b; 回答2: You can use these variables straight away in b.php require(), include(), etc...

How to correctly modularize a node.js project?

偶尔善良 提交于 2019-12-13 01:15:58
问题 I'm creating a node.js project following the class constructor pattern: function my_class(x,y){ this.x = x; this.y = y; } The starting point of the project is the main.js file. Any class of the project must be able to access global objects (such as "world" and "socket") which are defined on main.js . I found 4 options: I define my classes inside main.js . They'll have access to main.js 's globals for being on it's closure, but main.js will become bloated. I move the class to another file such

Reactjs require image url in variable is not working

99封情书 提交于 2019-12-12 19:10:06
问题 Strange problem I'm dynamically including the path to an image in the source directory. Putting the image directory in as a string works Fine (the part I commented out), but as soon as I put it in a variable it gives me the error " Cannot find module "."" var imageDir="assets/img/MyImage.png"; --Working // const imageData= require('assets/img/MyImage.png'); --Not Working const imageData= require(imageDir); Any one know why? Same-ish problem Here No answer unfortunately 回答1: Webpack needs to

PHP中include()和require()函数之间有什么区别?

邮差的信 提交于 2019-12-12 14:41:47
在PHP中include()和require()函数执行相同的功能,都可以帮助我们调用文件。那么它们之间有什么不同?下面本篇文章就来带大家了解一下include()和require()函数之间的区别,希望对大家有所帮助。 PHP include()函数 include()函数用于将函数内调用的文件内的所有内容(文本)复制到调用它的文件中;这发生在服务器超出代码之前。 示例:使用include()函数调用名为demo.php的文件 demo.php文件: <?php // 要包含的文件 echo "Hello PHP中文网!"; ?> 现在让我们尝试将此文件包含到另一个php文件(index.php)中。我们将看到文件的内容都显示出来。 index.php文件: <?php header("content-type:text/html;charset=utf-8"); include("demo.php"); echo "<br>包含上述文件" ?> 输出: PHP require()函数 require()函数与include()函数执行相同的操作。它还会获取所需的文件,并将整个代码复制到调用require()函数的文件中。 示例:使用require()函数调用名为demo.php的文件 demo.php文件 <?php // 要包含的文件 echo "PHP中文网!"; ?>

Crashes when calling `lua_getfield()` after overriding the require

孤人 提交于 2019-12-12 13:00:26
问题 This question is related to @Henri_Menke's answer from this question : How to get preloaded module name in C++ I'm trying to override the require function with my own version so I can get the preloaded module name inside Lua script. Here's my code: #include "lua.hpp" void main() { lua_State *L = luaL_newstate(); luaL_openlibs(L); lua_settop(L, 0); luaL_dostring(L, "local require_original = require\n" "function require(name, ...)\n" "current_module = name\n" "require_original(name, ...)\n"

NodeJS require('..')?

岁酱吖の 提交于 2019-12-12 09:49:23
问题 I've been looking through some NodeJS examples and I've encountered the following: var module = require('..'); var module = require('../'); I understand what require does, but I don't understand what it does when it's written like this. Can somebody explain it to me please? 回答1: This is the rule defined in https://nodejs.org/api/modules.html require(X) from module at path Y If X begins with './' or '/' or '../' a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) Since ../ or .. is not a file,

Failed to open stream: No such file or directory, yes there is!

守給你的承諾、 提交于 2019-12-12 08:36:28
问题 I've got a problem with requiring some files, PHP is telling me these files do not exist, but when I scan the directory it tells me it does exist. I've simplified the files to the require functionality, and it's still not working. Here is my setup: root/ test.php test/ test2.php sub/ test3.php test.php echo 'test'; require 'test/sub/test3.php'; test/test2.php (the file that for some reason doesn't get included) echo 'test2'; test/sub/test3.php echo 'test3'; /* because we are still on test.php

Resolving circular dependencies with Node.js require and classes in CoffeeScript

时光毁灭记忆、已成空白 提交于 2019-12-12 07:52:10
问题 I want to know if there is a way to idiomatically avoid issues with circular dependencies with Node.js's require while using CoffeeScript classes and super . Given the following simplified CoffeeScript files: a.coffee: C = require './c' B = require './b' class A extends C b: B someMethod: -> super module.exports = A b.coffee: C = require './c' A = require './a' class B extends C a: A someMethod: -> super module.exports = B The first obvious issue here is that there is a circular dependency