当我在 google chrome /students/student_name 的搜索栏中键入此内容时,我想获取数组列表的此名称
Posted
技术标签:
【中文标题】当我在 google chrome /students/student_name 的搜索栏中键入此内容时,我想获取数组列表的此名称【英文标题】:When I type this in my search bar in google chrome /students/student_name I want to get this name of the array list当我在 google chrome /students/student_name 的搜索栏中键入此内容时,我想获取数组列表的此名称 【发布时间】:2020-01-31 17:24:21 【问题描述】:这是我的代码,但我如何获得名称?
public function Class(Request $request)
$ClassList = ["Arian Drugzani", "Daniëlle Korterink", "Ilse Elskamp", "Janick Dragt", "Jens Bouma", "Marijn Boeve", "Mark Vos", "Mike Beekman", "Nick Bongers", "Ramon van Lohuizen", "Rutgher van de Vosse", "Sacha Veldhoen", "Sil Bosma", "Sophie Nieuwenhuis", "Thijmen de Lange", "Wessel Hakvoort"];
echo "<h1 style='font-family: sans-serif;'> Zoek resultaten voor: " . $request -> student . "<h1>";
foreach ($ClassList as $positie => $student)
echo "<h2>" . $positie. " ".$student . "<h2>";
return view('/students/student', ['ClassList' => $ClassList]);
路线如下:
Route::get('/students/student', 'JensController@Class');
【问题讨论】:
您使用echo
并返回视图。您的网站有一些强大的结构。
是的,这是学校的练习,我们必须这样做,但老师不想帮助我:/
它的 laravel 项目?
说得对
您也可以从视图中添加代码吗?并从名为 class 的函数中删除 echo,并将函数重命名为 getStudent 视图在resources/views/students/student.blade.php
【参考方案1】:
试试这个。您需要在函数Class($student_name)
中直接传递$student_name
。
还可以使用您的刀片视图文件路径更改/students/student
,例如如果文件名是学生则return view('students', ['ClassList' => $ClassList]);
public function Class($student_name)
$ClassList = ["Arian Drugzani", "Daniëlle Korterink", "Ilse Elskamp", "Janick Dragt", "Jens Bouma", "Marijn Boeve", "Mark Vos", "Mike Beekman", "Nick Bongers", "Ramon van Lohuizen", "Rutgher van de Vosse", "Sacha Veldhoen", "Sil Bosma", "Sophie Nieuwenhuis", "Thijmen de Lange", "Wessel Hakvoort"];
echo "<h1 style='font-family: sans-serif;'> Zoek resultaten voor: " . $student_name . "<h1>";
foreach ($ClassList as $positie => $student)
echo "<h2>" . $positie. " ".$student . "<h2>";
return view('/students/student', ['ClassList' => $ClassList]);
【讨论】:
是的,但我的意思是我想获取搜索栏的名称,以便将 $student_name 与位置一起从数组列表中取出。 在balde.view文件中你需要定义 route(students',$student)
【参考方案2】:
试试这个:
public function Class($student)
$classList = ["Arian Drugzani", "Daniëlle Korterink", "Ilse Elskamp", "Janick Dragt", "Jens Bouma", "Marijn Boeve", "Mark Vos", "Mike Beekman", "Nick Bongers", "Ramon van Lohuizen", "Rutgher van de Vosse", "Sacha Veldhoen", "Sil Bosma", "Sophie Nieuwenhuis", "Thijmen de Lange", "Wessel Hakvoort"];
$studentName = urldecode($student);
echo "<h1 style='font-family: sans-serif;'> Zoek resultaten voor: $studentName<h1>";
foreach($classList as $key => $name)
if ($studentName == $name)
echo "<h2>$key $name <h2>";
return view("students")->with("classList", $classList);
将return view("students")
中的学生替换为您的视图名称。
在你的 web.php 中
Route::get('/students/student', 'JensController@Class');
【讨论】:
以上是关于当我在 google chrome /students/student_name 的搜索栏中键入此内容时,我想获取数组列表的此名称的主要内容,如果未能解决你的问题,请参考以下文章
如何以 root 身份运行 Google Chrome? [关闭]
如何以root用户身份运行Google Chrome? [关闭]