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

Php: How to handle file processing and download operations in a single script?
PHP 5 - serializing objects and storing their relationship
CodeIgniter Auth System
Can someone please tell me how to escape an ampersand in PHP?
PHP function is_nan() throws a warning for strings
Displaying timezones without using UTC
Read header files and do something before full photo upload happens
autoload and multiple directories
Is it possible in PHP to escape newlines in strings as in C?
How to bootstrap Zend_Test_PHPUnit_ControllerTestCase with Zend_Application?
PHP: Remove unprintable characters without removing white space
PDO and nested fetching
Unpredictable log file writing in PHP
Get seconds until end of day in PHP
Validating XML from Twitter
linux file size

Categories

HOME
qt
android-fragments
key
add-on
nsview
vsts-build
supercollider
responsive-design
bellman-ford
elastic-load-balancer
azure-graph-api
amazon-emr
game-maker
mailgun
async-await
jqxgrid
fosuserbundle
unity-container
anova
workday
sharedpreferences
nurbs
web-push
high-availability
crud
source-insight
premake
actframework
cloveretl
keyboard-layout
microsoft-ui-automation
optionaldataexception
webalizer
return-type
deployd
image-registration
nusoap
sharpdx
winston
exc-bad-access
portability
apache-modules
google-shopping-api
mathml
rails-engines
maximize
simian
sharepoint-apps
openmrs
wepay
deeplink
bayesglm
smart-tv
decidable
largenumber
nastran
auto-generate
css-paged-media
domino-designer-eclipse
com0com
kotlin-android-extensions
subfolder
nanomsg
jcheckbox
xhprof
mobile-country-code
stripe.net
pageviews
typesafe-stack
particle-swarm
rautomation
codahale-metrics
statechart
web-frameworks
gprof
simplecov
email-verification
user-forums
border-box
server-name
firefly-mv
mygeneration
.net-services
google-translator-toolkit
efs
icon-language

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App