


Laravel 5 framework learning to transfer data to the view, laravel framework
We create a new route in Routes.php
Copy code The code is as follows:
Route::get('about', 'PagesController@about');
You will get an error when browsing in the browser. The error message is just a prompt message and lacks details. It's ok in the production environment, but we hope to get detailed information during the development stage.
Find the .env file in the root directory of the project and modify it
Copy code The code is as follows:
APP_DEBUG=true
This will display a detailed error message, PagesController does not exist. But in the production environment it must be set to false
We can create a new controller manually, but a faster way is to use the generator provided by laravel. Run in the current project directory from the command line:
Copy code The code is as follows:
php artisan
You can see the functions provided by laravel.
Copy code The code is as follows:
php artisan make:controller PagesController
ok, PagesController.php
is generated under app->http->controller<?php namespace App\Http\Controllers; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class PagesController extends Controller { /** * Display a listing of the resource. * * @return Response */ public function index() { // } /** * Show the form for creating a new resource. * * @return Response */ public function create() { // } /** * Store a newly created resource in storage. * * @return Response */ public function store() { // } /** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // } }
The controller generated in this way contains all the required RESTful methods, we can simplify it. Delete the generated PagesController.php and run it on the command line:
Copy code The code is as follows:
php artisan make:controller PagesController --plain
Take another look at the generated results
Copy code The code is as follows:
use AppHttpRequests;
use AppHttpControllersController;
use IlluminateHttpRequest;
class PagesController extends Controller {
//
}
Basically an empty controller, we need to create all the methods ourselves.
If you want to know what parameters we can execute on the command line, you can run the following command to view the help
Copy code The code is as follows:
php artisan help make:controller
ok, you can often use the help command to help you understand these parameters.
Establish the about method in PagesController.
Copy code The code is as follows:
public function about() {
return 'About Page';
}
Check the results in the browser, the error disappears and simple information is returned.
Back to view
Of course we want to return the html document and modify the return of the about method:
Copy code The code is as follows:
public function about() {
return view('pages.about');
}
Note: The returned result is pages.about , which means the about.balde.php file in the pages subdirectory within the views subdirectory. Let’s create the resourcesviewspagesabout.balde.php file
Copy code The code is as follows:
About
That's it. Run your browser to see,😄
Transfer data to the view
Modify PagesController.php
Copy code The code is as follows:
public function about() {
$name = 'Zhang Jinlgin';
return view('pages.about')->with('name', $name);
}
Modify our view file about.blade.php
Copy code The code is as follows:
About = $name ?>
Bingo, check the results.
The laravel we use uses blade templates, we can use this benefit to modify the view:
Copy code The code is as follows:
About {{ $name }}
Looks better. In blade, {{}} escapes the semantics of html. Let me modify a piece of data:
Copy code The code is as follows:
$name = 'Zhang Jinlgin';
View the results and find that all html elements have been escaped. But if you don’t need to escape html, you can use {!! !!} to modify the view:
Copy code The code is as follows:
About {!! $name !!}
Look at the results again,👌
The above is the entire content of this article. I hope it will help everyone master Laravel5.

iOS17中的Apple正在引入待机模式,这是一种新的显示体验,专为水平方向的充电iPhone而设计。处于这个位置的iPhone能够显示一系列全屏小部件,将其变成一个有用的家庭中心。待机模式会在水平放置在充电器上运行iOS17的iPhone上自动激活。您可以查看时间、天气、日历、音乐控制、照片等信息。您可以通过可用的待机选项向左或向右滑动,然后长按或向上/向下滑动以进行自定义。例如,随着时间的流逝,您可以从模拟视图、数字视图、气泡字体和日光视图中进行选择,其中背景颜色会根据时间而变化。有一些选项

在许多Web应用程序中,表格是必不可少的一个组件。表格通常具有大量数据,因此表格需要一些特定的功能来提高用户体验。其中一个重要的功能是可编辑性。在本文中,我们将探讨如何使用Vue.js实现可编辑的表格,并提供具体的代码示例。步骤1:准备数据首先,我们需要为表格准备数据。我们可以使用JSON对象来存储表格的数据,并将其存储在Vue实例的data属性中。在本例中

对比SpringBoot与SpringMVC,了解它们的差异随着Java开发的不断发展,Spring框架已经成为了许多开发人员和企业的首选。在Spring的生态系统中,SpringBoot和SpringMVC是两个非常重要的组件。虽然它们都是基于Spring框架的,但在功能和使用方式上却有一些区别。本文将重点对比一下SpringBoot与Sprin

Laravel是目前最流行的PHP框架之一,其强大的视图生成能力是让人印象深刻的一点。视图是Web应用程序中展示给用户的页面或视觉元素,其中包含HTML、CSS和JavaScript等代码。LaravelView允许开发者使用结构化的模板语言来构建网页,同时通过控制器和路由生成相应的视图。在本文中,我们将探讨如何使用LaravelView生成视图。一、什

PHP是一种非常流行的编程语言,而CodeIgniter4是一种常用的PHP框架。在开发Web应用程序时,使用框架是非常有帮助的,它可以加速开发过程、提高代码质量、降低维护成本。本文将介绍如何使用CodeIgniter4框架。安装CodeIgniter4框架CodeIgniter4框架可以从官方网站(https://codeigniter.com/)下载。下

我猜想,很多同学都想学习word的排版技巧,但小编偷偷告诉大家,在学习排版技巧之前需要先了解清楚word视图,在Word2007中提供了5种视图供用户选择,这5种视图包括页面视图、阅读版式视图、Web版式视图、大纲视图和普通视图,今天和小编了解一下这5种word视图吧。1.页面视图页面视图可以显示Word2007文档的打印结果外观,主要包括页眉、页脚、图形对象、分栏设置、页面边距等元素,是最接近打印结果的页面视图。2.阅读版式视图阅读版式视图以图书的分栏样式显示Word2007文档,Office

在Go中使用CGI,是一种常见的Web开发技术。本文将介绍如何在Go中使用CGI来实现Web应用程序。什么是CGI?CGI即通用网关接口(CommonGatewayInterface),是一种标准的Web服务器和其他应用程序之间进行交互的协议。通过CGI,Web服务器可以将请求发送给其他应用程序,然后接收其响应并将其发送回客户端。CGI是一种非常灵活和可

Django是一个高度可定制的Web框架,它提供了许多方便的工具和库,来帮助开发者快速创建高性能的、可扩展的Web应用程序。其中,视图是Django框架中最重要的组成部分之一。视图负责处理来自客户端的请求,并返回相应的响应。在本文中,我们将深入探讨Django框架中的视图,并介绍如何使用它来创建高性能、可定制的Web应用程序。一、视图的基本概念在Django


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
