我在这个论坛的某个地方找到了这个脚本,它运行正常。除非你想在后端使用文件夹。然后它再也不能正常工作了。所以现在我的根文件夹正在构建文件......有人可以查看这个脚本并帮助我吗?我不习惯PHP和MySQL,但学习......; - )
componentDidCatch
在标题内,链接形成如;
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = {
error: false
};
}
componentDidCatch() {
this.setState({ error: true});
}
render() {
return this.state.error
? "Error :("
: this.props.children;
}
}
const renderContent = () => {
throw new Error();
}
const Content = () => {
throw new Error();
}
// This will throw exception and not trigger error state
const Foo = () => (
<ErrorBoundary>
<div>{renderContent()}</div>
</ErrorBoundary>
);
// This will trigger the error state
const Bar = () => (
<ErrorBoundary>
<div><Content /></div>
</ErrorBoundary>
);
一切正常!但是如果你改变了最后一个代码;
<div id="content">
<?php
// All the page files, the first being the default value
$pages=array('page1','page2','page3','page4','page5','page6', 'page7', 'page8');
// Read $page variable from query string '?p='
$page=isset($_GET['p'])?$_GET['p']:$pages[0];
// Check if value of $page is allowed, assign default if not
if(!in_array($page,$pages))
{
$page=$pages[0];
}
include($page . '.php');
?>
</div>
它将不再起作用......
请帮忙......!
答案 0 :(得分:-1)
只需将chapters/
添加到包含路径:
include('chapters/' . $page . '.php');
保持HTML相同:
<a href="index.php?p=page1"></a>