首页 > 解决方案 > 过渡到像 article/show?id=1 这样的细节

问题描述

来自日本,对不起语法问题。

我想将页面从 index.php 转换为 show.php,这意味着如果用户单击索引中的“title1”,页面将转换 title1 的页面包含 title1 的一些详细信息。

目前我的情况

模型/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の一覧&lt;/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の&lt;?php print(htmlspecialchars($word['id'])); ?>個目の投稿&lt;/h1>
</div>

最后,如果你们都意识到我应该写另一种写代码的方式,比如“写这个更好”,请告诉我。

标签: phpurltransitionfuelphpfuel

解决方案


推荐阅读