微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决过渡到像文章/节目这样的细节?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 举报,一经查实,本站将立刻删除。