PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Aug 18, 2018 4:11 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Aug 18, 2015 3:35 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
I am building a small demo ecommerce website and basiclly have managed to build a small prototype. now i have main page, Here https://github.com/gautamz07/laravel-ec ... .blade.php , On the main page there are 4 products loaded (the latest products). now when you click on the inidivisual products , it takes you to the indivisual backpages of the product (https://github.com/gautamz07/laravel-ec ... .blade.php) .


You must be wondering how does clicking on the indivisual links take you to its backpages , if you have a closer look at the code on index.blade.php the href of each a tag looks like so:

Syntax: [ Download ] [ Hide ]
<a href="store/view/{{ $product->id }}">
.

have a look at the store controller here https://github.com/gautamz07/laravel-ec ... er.php#L17

did you notice the following method:

Syntax: [ Download ] [ Hide ]
public function getView($id) {
    return View::make('store.view')->with('product' , Product::find($id));
  }
 


I think the view part in the controller is calling getView() in the storeController, this is amusing to me, as how does laravel or php know how to map view (in the link ) to getView($id) function ??

Thank you.


Top
 Profile  
 
PostPosted: Tue Aug 18, 2015 3:39 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
You're using controller routing, so it's parsing the URI as /controller/action/params and prefixing the action with the HTTP verb used. Send a POST request to /store/view/123 and a different action would be triggered.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Aug 18, 2015 3:45 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
Quote:
You're using controller routing


what do you mean by that ?

Syntax: [ Download ] [ Hide ]
Send a POST request to /store/view/123 and a different action would be triggered.
 


I kind of realise that :) (though don't understand it totally yet)


Top
 Profile  
 
PostPosted: Tue Aug 18, 2015 3:51 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
gautamz07 wrote:
Quote:
You're using controller routing


what do you mean by that ?

https://github.com/gautamz07/laravel-ec ... es.php#L16

That.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Thu Aug 20, 2015 1:21 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 331
Thanks celauran :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group