php


How to acces value from route in symfony2


I have some newbie question. How can i access specific value from my Route.
This is my code:
/**
* Catch controller.
*
* #Route("catch")
*/
class CatchController extends Controller
{
/**
* #Route("/{id}")
* #Method({"GET"})
* #ParamConverter("advertisement", class="AffiliateBundle:Advertisement")
*/
public function goAction(Advertisement $advertisement)
{
//$advertisementId = $advertisement->getId();
//die($advertisementId);
//Creating new Lead
$elo = $advertisement->getId();
die($elo);
$lead = new Lead();
$lead ->setCreatedAt(new \DateTime());
$lead ->setUpdatedAt(new \DateTime());
//$lead ->setAdvertisement($advertisementId);
$add = $this->getDoctrine()->getManager();
$add->persist($lead);
$add->flush();
//Taking id of the created lead
$leadId = $lead->getId();
//Saving cookie in user's browser
$cookieValue = array(
'name' => 'leadcookie',
'value' => $leadId
);
$cookieLead = new Cookie($cookieValue['name'], $cookieValue['value']);
$response = new Response();
$response->headers->setCookie($cookieLead);
//Redirecting user to advertisement url.
$advertisementUrl = $advertisement->getUrlPattern();
return $this->redirect($advertisementUrl);
}
And when I call in my browser for example affiliate/catch/3 I can take every property from my Advertisement entity by it's methods. Like UrlPattern, RRSO, etc.
But i need to take ID of this advertisement and when i use getId() in my controller instead of 3 I'm getting nothing. How should i do it?
You can try this :
/**
* #Route("/{id}", requirements={"id" = "\d+"})
* #Method({"GET"})
* #ParamConverter("advertisement", class="AffiliateBundle:Advertisement")
*/
public function goAction(Advertisement $advertisement, $id) //add $id here
{
//your id is stocked in $id, do what you want with it
//I had "requirements" as your id must be a number
//...
}

Related Links

How to convert object format to json format in php
laravel,how i can change the code to return an array?
How to make At Least Two Field Required to fill in Laravel 5.2
How do I allow PHP to run when the script is not in the URL?
How to check if a file is BEING used, i.e. some command is being executed on the data in that file?
Display profile data from database when login
How to integrate laravel packages into an application
Log into a Django project using Magento user database SSO
Image not show in recyclerview from server
php table exporting it to excel [duplicate]
regex not closing span
How to use GroupBy in nested query in Laravel 5?
Laravel Users table Update
Which classes can I type-hint dependencies for automatic injection in Laravel 5?
Urlmanager ignores everything before index.php
Sharing complex objects across controller methods Laravel 5.1

Categories

HOME
extjs
libgdx
focus
yii
workflow
activemq
loopbackjs
embedded-resource
jersey-2.0
supercollider
fedora
ag-grid
phpmqtt
onvif
scheduler
getopenfilename
nsstring
sonata
jpa-2.0
twisted
web-deployment
nose
deepfreeze
cmake-gui
spring-shell
unity-container
exchange-server-2010
animated-gif
webviewclient
fstar
math.js
annotation-processing
xcrun
seafile-server
sql-execution-plan
ms-media-foundation
nest
creation
restful-architecture
buildforge
numerics
love2d
extbase
microkernel
swfupload
classnotfoundexception
hdiv
angular-datatables
dagger
virtual-memory
ipp-protocol
sonicmq
winston
spring.net
subforms
palindrome
email-forwarding
d3v4
researchkit
nunit-console
adp
uibinder
mnesia
gulp-uglify
i2b2
seadragon
gdl
helm
godeps
html.actionlink
largenumber
apache-commons-digester
bjam
android-studio-import
knife
fantom
dbmigrate
ildasm
cout
smacss
berkeley-db-xml
communicate
senchatouch-2.4
meteor-collections
pre
assetic
meteorite
discovery
simplecov
xcode4.5
zend-pdf
stretch
cakeyframeanimation
pcspim
kobold2d
kernel32
rtd
mongrel
j2mepolish
source-code-protection
gui-designer
community-server
service-factory

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App