我可以在以下位置设置PHP包含路径php.ini:
include_path = /path/to/site/includes/
Run Code Online (Sandbox Code Playgroud)
但其他网站受到影响,这是不好的.
我可以在每个文件的开头设置PHP include:
$path = '/path/to/site/includes/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
Run Code Online (Sandbox Code Playgroud)
但这似乎是不好的做法,并且使事情变得混乱.
所以我可以将其包含在内,然后将其包含在每个文件中:
include 'includes/config.php';
Run Code Online (Sandbox Code Playgroud)
要么
include '../includes/config.php';
Run Code Online (Sandbox Code Playgroud)
这就是我现在正在做的事情,但是包含路径config.php将根据包含的内容而改变.
有没有更好的办法?有关系吗?
我有一个包含几个表的模板.我想使用一个子模板,以相同的方式呈现这些表.我可以通过在视图中设置上下文并将其传递给模板来使其适用于单个表.但是,如何更改数据以呈现不同数据的另一个表?
**'myview.py'**
from django.shortcuts import render_to_response
table_header = ("First Title", "Second Title")
table_data = (("Line1","Data01","Data02"),
("Line2","Data03","Data03"))
return render_to_response('mytemplate.html',locals())
**'mytemplate.html'**
{% extends "base.html" %}
{% block content %}
<h2>Table 01</h2>
{% include 'default_table.html' %}
{% endblock %}
**'default_table.htm'**
<table width=97%>
<tr>
{% for title in table_header %}
<th>{{title}}</th>
{% endfor %}
</tr>
{% for row in table_data %}
<tr class="{% cycle 'row-b' 'row-a' %}">
{% for data in row %}
<td>{{ data }}</td>
{% endfor %}
</tr>
{% endfor %}
</table> …Run Code Online (Sandbox Code Playgroud) 总而言之,我在一个显示评论的网站上有动态页面.如果没有与特定城市/县/区域/等相关联的评论,则mysql查询返回0行,触发以下代码:
if (!$validRevQuery) {
header("HTTP/1.0 404 Not Found");
include("http://{$PDS['site']}/404.php?request=".urlencode($_SERVER['REQUEST_URI']));
exit;
}
Run Code Online (Sandbox Code Playgroud)
在某些webhost上,这会触发"URL文件访问被禁用"错误.这很好,但是在允许访问URL文件的文件上,404文件包含在内并正确显示.我稍微更改了代码以显示如下的绝对路径:
if (!$validRevQuery) {
header("HTTP/1.0 404 Not Found");
$_GET['request'] = urlencode($_SERVER['REQUEST_URI']);
include($_SERVER['DOCUMENT_ROOT']."/404.php");
exit;
}
Run Code Online (Sandbox Code Playgroud)
而现在,它给了我通用的"哎呀!这个链接似乎被打破了." 错误页面.(我有谷歌工具栏,所以这可能会有所不同,具体取决于浏览器和插件).不知道为什么会这样,所以任何帮助都表示赞赏!
我正在尝试编写一个Arduino库(实际上是一个C++类),它本身引用了我在Mac的〜/ Documents/Arduino/libraries目录中安装的另一个库.
在我正在写的图书馆的.cpp的顶部,我试过了
#include <ReferencedLibrary.h>
Run Code Online (Sandbox Code Playgroud)
和
#include "ReferencedLibrary.h"
Run Code Online (Sandbox Code Playgroud)
......两者都不起作用.我可以#include <ReferencedLibrary.h>在〜/ Documents/Arduino目录中成功绘制草图.我错过了什么或者这是Arduino IDE/makefile的限制吗?有解决方法吗?
我在Eclipse CDT main和共享中有两个c ++项目.在共享中我有一个名为calc.h的标题.我想在main中使用这个头,所以我做了以下事情:
#include "calc.h到main中的相关文件中properties -> Project references我检查共享我希望这可以工作,但是我fatal error: calc.h: No such file or directory在编译时得到了,所以项目参考不知何故不起作用.
我可以得到它通过手动添加工作共享的源文件夹中的主要的properties->C/C++ Build->Setting->GCC C++Compiler->Includes,但我的我有一种不好的预感,这将成为较大的项目更加复杂的依赖关系繁琐.因此,我希望Eclipse可以通过项目引用来处理这个问题.
我错过了什么或手动是唯一的方法吗?
假设我们有两个php文件,a.php和b.php这里是文件a.php的内容:
<?php // content of a.php
class A {
}
Run Code Online (Sandbox Code Playgroud)
这是文件b.php的内容
<?php // content of b.php
include dirname(__FILE__) . "/a.php";
echo "A: ", class_exists("A") ? "exists" : "doesn’t exist", "\n";
echo "B: ", class_exists("B") ? "exists" : "doesn’t exist", "\n";
echo "BA (before): ", class_exists("BA") ? "exists" : "doesn’t exist", "\n";
echo "BB: ", class_exists("BB") ? "exists" : "doesn’t exist", "\n";
class B {
}
class BA extends A {
}
class BB extends B {
}
echo "BA (after): …Run Code Online (Sandbox Code Playgroud) 我有这些文件
consumer.cpp
consumer.hpp
defines.hpp
main.cpp
makefile
producer.cpp
producer.hpp
Run Code Online (Sandbox Code Playgroud)
这是define.hpp文件
#ifndef DEFINES_HPP
#define DEFINES_HPP
#include <cassert>
#include <pthread.h>
#include <queue>
#include <stdlib.h>
#include <string>
#include <unistd.h>
pthread_mutex_t set_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t condition_var = PTHREAD_COND_INITIALIZER;
std::queue<int> q;
#endif // DEFINES_HPP
Run Code Online (Sandbox Code Playgroud)
这个defined.hpp文件包含在producer.hpp和consumer.hpp中.producer.hpp和consumer.hpp文件分别包含在producer.cpp和consumer.cpp中,还包括main.cpp中.编译时我得到一个错误.
g++ -o main producer.cpp consumer.cpp main.cpp producer.hpp consumer.hpp defines.hpp -lpthread -ggdb
/tmp/ccctuRp7.o: In function `__gnu_cxx::new_allocator<int>::destroy(int*)':
/home/vardan/test/consumer.cpp:8: multiple definition of `set_queue_mutex'
/tmp/cciGccft.o:/home/vardan/test/producer.cpp:8: first defined here
/tmp/ccctuRp7.o: In function `std::deque<int, std::allocator<int> >::front()':
/home/vardan/test/consumer.cpp:12: multiple definition of `condition_var'
/tmp/cciGccft.o:/home/vardan/test/producer.cpp:11: first defined here
/tmp/ccctuRp7.o: In …Run Code Online (Sandbox Code Playgroud) 我的网站上有一个名为$ basePath的变量,它被设置为:
$basePath = '/Systems/dgw/';
Run Code Online (Sandbox Code Playgroud)
我在我的所有css,js和图像标签上使用它(缩短以获得更好的可见性):
<link href="<?php echo $basePath; ?>include/assets/css/bootstrap.min.css">
Run Code Online (Sandbox Code Playgroud)
我对这些包含没有问题,它们可以在任何文件和我的文件夹中正常工作.
我有一个包含以下行的页面:
<img src="<?php echo $basePath; ?>images/new_logo.png" alt="logo"/>
Run Code Online (Sandbox Code Playgroud)
图像显示很好.之后的一行说明:
<?php include($basePath.'include/assets/common/topMessages.php');?>
Run Code Online (Sandbox Code Playgroud)
但包含不会发生.当我这样尝试时:
<?php include('../../include/assets/common/topMessages.php');?>
Run Code Online (Sandbox Code Playgroud)
有用.
任何人都知道什么可能是错的?
我有一个/patterns在我的Jekyll网站中调用的目录,其结构通常看起来像这样:
_includes
_layouts
_site
/patterns
index.html
我需要将/patterns目录保留在外面_includes有很多原因,但主要是因为我需要将文件拉/patterns入iframe以显示在模式库中).
我想/patterns在我的Jekyll页面中包含文件,但是使用{% include /patterns/file.html %} doesn't work as it points to the_includes folder. How would I go about including a file from a directory that isn't_includes`?
假设首先使用这些模型:
Method有一个OriginalCode
OriginalCode有很多Mutants
Mutant有很多ParseSubTrees的
现在在查询时Method我希望另一个被加载.所以我有以下内容:
Method targetMethod = dBContext.Methods
.Include(me => me.OriginalCode)
.ThenInclude(oc => oc.Mutants)
.FirstOrDefault(me => me.Id == id);
Run Code Online (Sandbox Code Playgroud)
并且下一步是另外包括ParseSubTree.但问题是我无法访问它.请参见以下图像:
问题是"mu是列表而不是对象引用"!
我的错误在哪里!
TG.