Tefito

Laravel: He aha nga Tirohanga laravel

I roto i te anga MVC, ko te reta "V" e tu ana mo nga Tirohanga, i roto i tenei tuhinga ka kite tatou me pehea te whakamahi i nga tirohanga i Laravel. Wehea te arorau tono me te arorau whakaaturanga. Ka penapenahia nga tirohanga ki te raarangi rauemi/tirohanga. Ko te tikanga, kei roto i te tirohanga te HTML ka tukuna ki te tirotiro.

tauira

Tirohia te tauira e whai ake nei kia mohio ai koe mo nga Tirohanga

1 – Tāruatia te waehere e whai ake nei ka penapena ki roto rauemi/views/test.blade.php

<html>
   <body>
      <h1>Laravel Blog Innovazione</h1>
   </body>
</html>

2 – Taapirihia te rarangi e whai ake nei ki te konae route/web.php hei whakarite i te ara mo te tirohanga i runga.

Route::get('/test', function() {
   return view('test');
});

3 – I roto i te pūtirotiro ka whakatuwherahia e matou te wharangi i te URL kia kite i te putanga o te tirohanga.

http://localhost:8000/test

Ko te hua ka kite tatou i te tuhi "Laravel Blog Innovazione” i te taitara h1

Te wāhi noho http://localhost:8000/test whakaturia i roto i te pūtirotiro ka arahi ki te ara test kua tohua i te wahanga tuarua, e karanga ana i te tirohanga test.blade.php kua tohua i te wahanga 1.

Te tuku raraunga ki nga tirohanga

I a koe e hanga ana i to tono, me tuku raraunga ki nga tirohanga. 

tauira

Hei kite me pehea te tuku raraunga ki nga tirohanga, me haere tonu me tetahi tauira:

1 – Tāruatia te waehere e whai ake nei ka penapena ki roto rauemi/views/test.blade.php

<html>
   <body>
      <h1><?php echo $name; ?></h1>
   </body>
</html>

2 – Ka taapirihia e matou te rarangi e whai ake nei ki te konae route/web.php hei whakarite i te ara mo te tirohanga i runga.

Route::get('/test', function() {
   return view('test',[‘name’=>’Laravel Blog Innovazione’]);
});

3 – Te uara e hāngai ana ki te kī 'name' ka tukuna ki te konae test.blade.php ka whakakapia te ingoa $ingoa ki taua uara.

4 – Me toro atu ki te URL e whai ake nei kia kite i te putanga o te tirohanga.

http://localhost:8000/test

5 – Ko te putanga ka puta i roto i te kaitirotiro me te tuhi rite ki te tauira tuatahi, ara ko te tuhi “Laravel Blog Innovazione” i te taitara h1

Panui houtanga
Kaua e ngaro nga korero tino nui mo te mahi auaha. Waitohu ki te whiwhi i a raatau ma te imeera.

Te tiri raraunga me nga tirohanga katoa

Kua kite matou me pehea te tuku raraunga ki nga tirohanga, engari i etahi wa me tuku raraunga ki nga tirohanga katoa. Ko Laravel he ngawari ake. He tikanga e kiia ana share() ka taea te whakamahi mo tenei kaupapa. Ko te tikanga share() e rua nga tohenga, te matua me te uara. Ko te tikanga share() ka taea te waea mai i te tikanga whakaoho a te kaiwhakarato ratonga. Ka taea e matou te whakamahi i tetahi kaiwhakarato ratonga, AppServiceProvider ta tatou ranei service provider.

tauira

Tirohia te tauira e whai ake nei kia maarama ake mo te tiri raraunga me nga tirohanga katoa -

1 – Taapirihia te rarangi e whai ake nei ki te konae app/Http/routes.php .

app/Http/paths.php

Route::get('/test', function() {
   return view('test');
});

Route::get('/test2', function() {
   return view('test2');
});

2 - Ka hangaia e matou nga konae tirohanga e rua: whakamātautau.blade.php e whakamātautau2.blade.php me te waehere kotahi. Ko enei nga konae e rua ka tohatoha nga raraunga. Tāruatia te waehere e whai ake nei ki ngā kōnae e rua. resources/views/test.blade.php e resources/views/test2.blade.php

<html>
   <body>
      <h1><?php echo $name; ?></h1>
   </body>
</html>

3 – Hurihia te waehere tikanga whawhai i roto i te konae app/Providers/AppServiceProvider.php e whakaaturia ana i raro nei. (I konei, kua whakamahia e matou te tikanga tiritiri me nga raraunga i tukuna e maatau ki nga tirohanga katoa.) 

app/Providers/AppServiceProvider.php

<?php

namespace App\Providers;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider {
   
   /**
      * Bootstrap any application services.
      *
      * @return void
   */

   public function boot() {
      view()->share('name', 'Laravel Blog Innovazione');
   }

   /**
      * Register any application services.
      *
      * @return void
   */

   public function register() {
      //
   }
}

4 - Visita nga URL e whai ake nei.

http://localhost:8000/test
http://localhost:8000/test2

5 – Ko te putanga ka puta i roto i te kaitirotiro me nga tuhinga rite ki nga tauira tuatahi me te tuarua, ara ko te tuhi "Laravel Blog Innovazione” i te taitara h1

Ercole Palmeri

Ka hiahia pea ratou ki enei mea:

Panui houtanga
Kaua e ngaro nga korero tino nui mo te mahi auaha. Waitohu ki te whiwhi i a raatau ma te imeera.

Nga tuhinga o mua

Te wawaotanga auaha i roto i te Reality Whakanuia, me tetahi kaitirotiro Apple i te Catania Polyclinic

I mahia he mahi ophthalmoplasty ma te whakamahi i te kaimataki arumoni Apple Vision Pro i te Catania Polyclinic…

3 May 2024

Nga Hua o nga Wharangi Tae mo nga Tamariki - he ao makutu mo nga reanga katoa

Ko te whakawhanake i nga pukenga motuka pai na roto i te tae ka whakarite i nga tamariki mo nga pukenga uaua ake penei i te tuhi. Ki te tae…

2 May 2024

Kei konei te heke mai: Me pehea te Ahumahi kaipuke e huri ana i te ohanga o te ao

Ko te waahanga moana he mana ohaoha pono o te ao, kua whakatere ki te maakete 150 piriona ...

1 May 2024

Ka haina nga Kaiwhakaputa me te OpenAI i nga whakaaetanga hei whakahaere i te rere o nga korero i tukatukahia e Artificial Intelligence

I te Mane kua hipa, i panuitia e te Financial Times tetahi mahi me OpenAI. Ka raihana a FT i tana kairipoata o te ao…

30 Paenga-whāwhā 2024