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.

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

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题