dongqi9125 2015-12-11 18:58
浏览 78
已采纳

URL id等于if语句或elseif语句打开页面

1- Work correct in this step

this url work

This is correct work enter image description here

2- Work not in this step

help me in this step

index.blade.php page

navbar code

 <nav class="navigation">
          <ul class="sf-menu">
            <li><a href="{{ url('/') }}">Home</a>
            </li>
            <li><a href="{{ url('about') }}">About Us</a></li>
            <li><a href="javascript:;">Category</a>
              <ul class="dropdown">
                <li><a href="{{ url('grid/1') }}">Buy and Sell</a></li>
                <li><a href="agent-detail.html">Car and Vehicles</a></li>
                <li><a href="my-properties.html">Real Estate</a></li>
                <li><a href="submit.html">Pets</a></li>
                <li><a href="pricing.html">Jobs</a></li>
                <li><a href="login.html">Community</a></li>
                <li><a href="404.html">Resumes</a></li>
              </ul>
            </li>
  1. problem in this anchor tag (1) pass to URL enter image description here

My Route code

Route::resource('/', 'BasicController');
Route::resource('about', 'BasicController@about');
Route::resource('contact', 'BasicController@contact');
Route::resource('grid', 'BasicController@grid');

This is my controller code

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class BasicController extends Controller
{
    public function index(){  
        return view('index');
    }
    public function about(){   
       return view('about');
    }

    public function contact(){
       return view('contact');
    }
     public function grid($id)
{  
    $id = $this->uri->segment(3);

    if ($id == 1) {
       return view('buy-and-sell/grid');
    }
    elseif ($id == 2) {
        return view('car-and-vehicels/grid');
    }
    elseif ($id == 3) {
        return view('country/grid');
    }
    else{
         return view('other/grid');
    }

  }
}

click on buy and sell enter image description here

To Face this problem

  1. First problem enter image description here

    BasicController

    public function grid($id) {

    $id = $this->uri->segment(3); <!-- Line number 30-->
    
    if ($id == 1) {
       return view('buy-and-sell/grid');
    }
    elseif ($id == 2) {
       return view('car-and-vehicels/grid');
    }
    elseif ($id == 3) {
       return view('country/grid');
    }
    else{
       return view('other/grid');
    } 
    

    }

  2. second problem enter image description here

  • 写回答

1条回答 默认 最新

  • doulangxun7769 2015-12-12 02:48
    关注

    You have to apply the following changes:

    1.) Your method signature is wrong. See below, Laravel will pass in the "number" automatically from your url in the variable $id (but as second(!) argument). Be ware you also have to import the Request in the header via an use Illuminate\Http\Request; statement!

    public function grid(Request $request, $id)
    

    2.) Dont use $this->uri->segment but rather use the passed $id directly (this is the slug that represents segement 3). You are using resource Controllers and Laravel does the mapping automatically for you.

    So it should look likes this:

    public function grid(Request $request, $id)
        {  
            //$id = $this->uri->segment(3); //COMMENT THIS OUT!!!
    
            if ($id == 1) {
               return view('buy-and-sell/grid');
            }
            elseif ($id == 2) {
                return view('car-and-vehicels/grid');
            }
            elseif ($id == 3) {
                return view('country/grid');
            }
            else{
                 return view('other/grid');
            }
    

    3.) Regarding the CSS. You got your paths wrong, but this is extremely hard to debug/help without further information

    Important: Its seems you are running laravel as a subfolder install. You will run into very strange problems (like this one, I suspecte this the subfolder install could be the reason). I have opened a bug at laravel some time ago, but it got closed. Subfolder Installs are not supported.

    I really advise you to install laravel as described on their homepage as a dedicated virtual host, that the public folder maps to the domain itself (like http://localhost) in other words "public" is your root folder that is served directly under http:://localhost.

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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记