Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建一个PHP laravel控制器以加载视图_Php_Laravel - Fatal编程技术网

创建一个PHP laravel控制器以加载视图

创建一个PHP laravel控制器以加载视图,php,laravel,Php,Laravel,在codeigniter上工作了一段时间后,我们开始了一个关于Laravel的项目,但我一开始就被卡住了 我无法理解,我在哪里定义了选择工作所需控制器的路径: 定义主控制器路径加载->My_first_proyect.php 无法理解从我的资源/views.balde.php加载视图的位置: 控制器我的第一个端口: 索引->加载视图->view.blade.php 如果我的问题是基本的,谢谢,对不起。您将从相应的控制器方法中加载视图。例如: public function index() {

codeigniter上工作了一段时间后,我们开始了一个关于Laravel的项目,但我一开始就被卡住了

我无法理解,我在哪里定义了选择工作所需控制器的路径: 定义主控制器路径加载->My_first_proyect.php

无法理解从我的资源/views.balde.php加载视图的位置: 控制器我的第一个端口: 索引->加载视图->view.blade.php


如果我的问题是基本的,谢谢,对不起。

您将从相应的控制器方法中加载视图。例如:

public function index()
{

    $employees = Employee::all();

    return view('employees.index')->with('employees', $employees);

}
Laravel将把
employees.index
翻译成
resources/views/employees/index.blade.php

接下来,您将修改
routes/web.php
文件。您可以用多种不同的方式定义路由,但是对于大多数用例,您可能希望将控制器定义为,因此路由定义如下所示:

Route::resource('employees', 'EmployeeController');
这意味着您的
索引
视图可以通过HTTP调用
/employees/
访问


希望这能有所帮助。

您使用的是哪种版本的Laravel?从Laravel 5开始,您应该在routes/web.php文件中定义路由和控制器

web.php

<?php

namespace App\Http\Controllers;

use App\User;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return View
     */
    public function show($id)
    {
        return view('user.profile', ['user' => User::findOrFail($id)]);
    }
}
Route::get('user/{id}','UserController@show');

app\Http\Controllers\UserController

<?php

namespace App\Http\Controllers;

use App\User;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return View
     */
    public function show($id)
    {
        return view('user.profile', ['user' => User::findOrFail($id)]);
    }
}

嘿,太多了!,这对我帮助很大,但是在哪里可以添加这一行来添加我的函数索引呢?“routes/web.php”我想是为了确定要查看的主视图,还是在那里添加主控制器?我不想在拉雷维尔成为新来的,所有这些听起来都很基本,从这里开始,非常感谢你对我的帮助,克劳斯瓦加斯,我修改了回答,以回答你接下来的问题。