php - 过渡到像 article/show?id=1 这样的细节
问题描述
来自日本,对不起语法问题。
我想将页面从 index.php 转换为 show.php,这意味着如果用户单击索引中的“title1”,页面将转换 title1 的页面包含 title1 的一些详细信息。
目前我的情况
- 可以像数据库一样连接MyAdminSql
- 可以在索引页面(localhost/words/index.php)中查看数据库中的所有单词
- 正如您在 index.php 中看到的“a tag”,但是当我单击单词的每个链接时,页面无法显示。URL 正在获取 (localhost/words/show?id=1)
模型/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();
}
}
/控制器/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>
最后,如果你们都意识到我应该写另一种写代码的方式,比如“写这个更好”,请告诉我。
解决方案
推荐阅读
- angular - ionic4 形式的密码和确认密码匹配验证
- html - 如何减少wordpress中的页脚大小
- python - pygame.QUIT 未定义
- json - 如何构造单个 JSON,其中 column1 是属性名称,column2 是值
- java - 如何通过 MainFrame 中的事件侦听器将 JPanel 作为组件添加到另一个类
- sql - 在具有多个总和的多个列上进行透视
- java - 将 EJB 2.1 从 Weblogic 迁移到 JBoss EAP 7.2
- ksqldb - ksql-server 指标名称在服务 ID 后缺少下划线
- java - Swagger 未从运行时检测参数
- node.js - 我的 Docker 多阶段脚本中有错误