过渡到像文章/节目这样的细节?id=1

问题描述

来自日本,抱歉语法问题。

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

目前我的情况

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 (将#修改为@)