如何解决过渡到像文章/节目这样的细节?id=1
来自日本,抱歉语法问题。
我想将页面从 index.PHP 转换为 show.PHP,这意味着如果用户单击索引中的“title1”,页面将转换为 title1 的页面,其中包含 title1 的一些详细信息。
目前我的情况
- 可以像数据库一样连接 MyAdminsql
- 可以在索引页 (localhost/words/index.PHP) 中查看数据库中的所有单词
- 正如你在 index.PHP 中看到的“一个标签”,但是当我点击单词的每个链接时,页面无法显示。 URL 正在获取 (localhost/words/show?id=1)
model/words.PHP
<?PHP
use Fuel\Core\Model;
class Model_Words extends Model
{
public static function all_words()
{
return DB::select()->from('words')->execute()->as_array();
}
public static function one_word($id)
{
return DB::select()->from('words','users')->where('id','=',$id)->execute()->as_array();
}
}
/controller/words.PHP
<?PHP
use Fuel\Core\Model;
use Fuel\Core\Request;
use Fuel\Core\Response;
class Controller_Words extends Controller_Base
{
public function action_index()
{
$data = array();
$words = Model_Words::all_words();
$data['words'] = $words;
$this->template->content = View::forge('words/index',$data);
}
public function action_show(Request $id)
{
$data = array();
$word = Model_Words::one_word($id);
$data['word'] = $word;
$this->template->content = View::forge('words/show',$data);
}
}
/views/words/index.PHP
<div>
<h1>Wordsの一覧</h1>
<table>
<thead>
<tr>
<td><span></span></td>
<td>word</td>
</tr>
</thead>
<tbody>
<?PHP foreach ($words as $word) : ?>
<tr>
<td>
<?PHP print(htmlspecialchars($word['id'],ENT_QUOTES)); ?>回目
</td>
<td>
<a href="show?id=<?PHP print(htmlspecialchars($word['id'])); ?>">
<?PHP print(htmlspecialchars($word['word'],ENT_QUOTES)); ?>
</a>
</td>
</tr>
<?PHP endforeach; ?>
</tbody>
</table>
</div>
/views/words/show.PHP
<div>
<h1>Wordsの<?PHP print(htmlspecialchars($word['id'])); ?>個目の投稿</h1>
</div>
最后,如果你们都意识到我应该写另一种写代码的方式,比如“写这个更好”,请告诉我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。