dongtu1958 2016-06-23 12:43
浏览 11
已采纳

页面已更改,但内容在laravel中保持相同

The problem is that I load dynamically menu pages from database. And whenever I click on the page load only page_id=1 and content... For example if I click page_id=5 will load again first result from database table. In browser address bar I see that id is changed but not on the page.

This is what I have so far.. route

Route::get ('/static/page/{pageId}', ['uses' => 'HomeController@page']);

In HomeController page looks like this

public function page() {

          $pages = Pages::all();
          return View::make('site.page', [            
              'pages' => $pages
          ]); 
}

in page.blade.php I have this

@extends('layouts.master')
@foreach($pages as $page)
    @section('title', $page->page_title)

    <div class="col-xs-12">
        <h3>{{ $page->page_title }}</h3>
        <hr />

        <div class="row">
            {{ $page->page_body }}
        </div>

        <hr />
    </div>
    @endsection
@endforeach

Button which lead to page.blade

<li><a href="{{ URL::to('/static/page/'.$page->page_id) }}">{{ $page->page_title }}</a></li>
  • 写回答

1条回答 默认 最新

  • donglue8180 2016-06-23 12:46
    关注

    You're not using the pageID anywhere. You need to pass it into the function, then use it in the query.

    public function page($pageID) {
    
          $page = Pages::findOrFail($pageID);
          return View::make('site.page', [            
              'pages' => $page
          ]); 
    }
    

    Then you can use the single page object on your page.blade.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败