我使用搜索查询日志制作了简单的搜索表单。
在我的indexAction
中public function indexAction(){
$searchLog = new SearchLog;
$form = $this->createFormBuilder($searchLog)
->add('query','text')
->add('save', 'submit', array('label' => 'Search'))
->setAction($this->generateUrl('acme_top_searchResult'))
->getForm();
'acme_top_searchResult'调用searchResultAction(); 我在searchResultAction
中收到了查询public function searchResultAction(Request $request){
//var_dump($request);
$searchLog = new SearchLog;
$form = $this->createFormBuilder($searchLog)
->add('query')
->getForm();
$form->handleRequest($request);
$queryData = $form->getData();
$this->em->persist($searchLog);
$this->em->flush();
$sq = $queryData->getQuery(); // use $sq for searching
但是它在数据库中插入了两行。为什么会发生?
我试过了。
public function searchResultAction(Request $request){
$searchLog = new SearchLog();
$form = $this->createFormBuilder($searchLog)
->add('query')
->getForm();
$form->handleRequest($request);
if ($form->isValid()){// however it dose not return true
然而$ form-> isValid()不会返回true
我在下面粘贴了var_dump($ request)日志。
看起来像提交做得很好...... 谁能帮帮我???object(Symfony\Component\HttpFoundation\Request)[3]
public 'attributes' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[6]
protected 'parameters' =>
array (size=3)
'_controller' => string 'Acme\TopBundle\Controller\DefaultController::searchResultAction' (length=63)
'_route' => string 'acme_top_searchResult' (length=21)
'_route_params' =>
array (size=0)
empty
public 'request' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[4]
protected 'parameters' =>
array (size=1)
'form' =>
array (size=3)
'query' => string 'rarara' (length=6)
'save' => string '' (length=0)
'_token' => string 'QUF1ZJU3EVTvnC3LKfdQR2z_-OuQnG2FTDs8vrTGucs' (length=43)
public 'query' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[5]
protected 'parameters' =>
array (size=0)
empty
public 'server' =>
object(Symfony\Component\HttpFoundation\ServerBag)[9]myApp
protected 'parameters' =>
array (size=37)
'HTTP_HOST' => string 'localhost' (length=9)
'HTTP_CONNECTION' => string 'keep-alive' (length=10)
'CONTENT_LENGTH' => string '99' (length=2)
'HTTP_CACHE_CONTROL' => string 'max-age=0' (length=9)
'HTTP_ACCEPT' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' (length=74)
'HTTP_ORIGIN' => string 'http://localhost' (length=16)
'HTTP_USER_AGENT' => string 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36' (length=121)
'CONTENT_TYPE' => string 'application/x-www-form-urlencoded' (length=33)
'HTTP_REFERER' => string 'http://localhost/myApp/web/app_dev.php/' (length=43)
'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate' (length=13)
'HTTP_ACCEPT_LANGUAGE' => string 'ja,en-US;q=0.8,en;q=0.6' (length=23)
'HTTP_COOKIE' => string 'PHPSESSID=iqpa901b7sfurcs9kvlkis3v52' (length=36)
'PATH' => string '/usr/bin:/bin:/usr/sbin:/sbin' (length=29)
'SERVER_SIGNATURE' => string '' (length=0)
'SERVER_SOFTWARE' => string 'Apache/2.4.9 (Unix) PHP/5.6.9' (length=29)
'SERVER_NAME' => string 'localhost' (length=9)
'SERVER_ADDR' => string '::1' (length=3)
'SERVER_PORT' => string '80' (length=2)
'REMOTE_ADDR' => string '::1' (length=3)
'DOCUMENT_ROOT' => string '/Users/MyName/CodingWorks/httproot' (length=34)
'REQUEST_SCHEME' => string 'http' (length=4)
'CONTEXT_PREFIX' => string '' (length=0)
'CONTEXT_DOCUMENT_ROOT' => string '/Users/MyName/CodingWorks/httproot' (length=34)
'SERVER_ADMIN' => string 'you@example.com' (length=15)
'SCRIPT_FILENAME' => string '/Users/MyName/CodingWorks/httproot/myApp/web/app_dev.php' (length=60)
'REMOTE_PORT' => string '51319' (length=5)
'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
'REQUEST_METHOD' => string 'POST' (length=4)
'QUERY_STRING' => string '' (length=0)
'REQUEST_URI' => string '/myApp/web/app_dev.php/sr' (length=29)
'SCRIPT_NAME' => string '/myApp/web/app_dev.php' (length=26)
'PATH_INFO' => string '/sr' (length=3)
'PATH_TRANSLATED' => string '/Users/MyName/CodingWorks/httproot/sr' (length=37)
'PHP_SELF' => string '/myApp/web/app_dev.php/sr' (length=29)
'REQUEST_TIME_FLOAT' => float 1436891356.666
'REQUEST_TIME' => int 1436891356
public 'files' =>
object(Symfony\Component\HttpFoundation\FileBag)[8]
protected 'parameters' =>
array (size=0)
empty
public 'cookies' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[7]
protected 'parameters' =>
array (size=1)
'PHPSESSID' => string 'iqpa901b7sfurcs9kvlkis3v52' (length=26)
public 'headers' =>
object(Symfony\Component\HttpFoundation\HeaderBag)[10]
protected 'headers' =>
array (size=13)
'host' =>
array (size=1)
0 => string 'localhost' (length=9)
'connection' =>
array (size=1)
0 => string 'keep-alive' (length=10)
'content-length' =>
array (size=1)
0 => string '99' (length=2)
'cache-control' =>
array (size=1)
0 => string 'max-age=0' (length=9)
'accept' =>
array (size=1)
0 => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' (length=74)
'origin' =>
array (size=1)
0 => string 'http://localhost' (length=16)
'user-agent' =>
array (size=1)
0 => string 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36' (length=121)
'content-type' =>
array (size=1)
0 => string 'application/x-www-form-urlencoded' (length=33)
'referer' =>
array (size=1)
0 => string 'http://localhost/myApp/web/app_dev.php/' (length=43)
'accept-encoding' =>
array (size=1)
0 => string 'gzip, deflate' (length=13)
'accept-language' =>
array (size=1)
0 => string 'ja,en-US;q=0.8,en;q=0.6' (length=23)
'cookie' =>
array (size=1)
0 => string 'PHPSESSID=iqpa901b7sfurcs9kvlkis3v52' (length=36)
'x-php-ob-level' =>
array (size=1)
0 => int 1
protected 'cacheControl' =>
array (size=1)
'max-age' => string '0' (length=1)
protected 'content' => null
protected 'languages' => null
protected 'charsets' => null
protected 'encodings' => null
protected 'acceptableContentTypes' => null
protected 'pathInfo' => string '/sr' (length=3)
protected 'requestUri' => string '/myApp/web/app_dev.php/sr' (length=29)
protected 'baseUrl' => string '/myApp/web/app_dev.php' (length=26)
protected 'basePath' => null
protected 'method' => string 'POST' (length=4)
protected 'format' => null
protected 'session' =>
object(Symfony\Component\HttpFoundation\Session\Session)[58]
protected 'storage' =>
object(Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage)[57]
protected 'bags' =>
array (size=2)
'attributes' =>
object(Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag)[435]
private 'name' => string 'attributes' (length=10)
private 'storageKey' => string '_sf2_attributes' (length=15)
protected 'attributes' => &
array (size=5)
'_csrf/form' => string 'QUF1ZJU3EVTvnC3LKfdQR2z_-OuQnG2FTDs8vrTGucs' (length=43)
'_locale' => string 'en' (length=2)
'_csrf/authenticate' => string 'ojhFU-vZUjlbBmAyza7fKnYsd_Oam_M1e35W_-qJkHE' (length=43)
'_security_main' => string 'C:68:"HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken":1098:{a:7:{i:0;s:218:"CAAFDj1Jc7IABAEpHpntZBDjZAIb74QGEsL5K0CEWWvGHNfnk7kGrYTzN9ssMfa6PasjIMsuDXhHlulqSxXeRLLrkxTPAaxu7ygoMeGlahUjK6UDB8nRCtHhtkJdlWxpgSFy3ESeGW9dPgbZAWisEdR5xiTnwaB6B6xk4EGxlOQ8vMZCZBeBJ4ZBJ5rghCpeZCseLUF6ZAAzSvk7rZBisDHg7j";i:1;a:2:{s:12:"access_token";s:218:"CAAFDj1Jc7IABAEpHpntZBDjZAIb74QGEsL5K0CEWWvGHNfnk7kGrYTzN9ssMfa6PasjIMsuDXhHlulqSxXeRLLrkxTPAaxu7ygoMeGlahUjK6UDB8nRCtHhtkJdlWxpgSFy3ESeGW9dPgbZAWisEdR5xiTnwaB6B6xk4EGxlOQ8vMZCZBeBJ4ZBJ5rghCpeZCseLUF6ZAAzSvk7rZBisDHg7j";s:7:"expires";s:7:"5150639";}i:2;N;i:3;s:7:"5150639";i:4;i:1436891127;i:5;s:8:"facebook";i:6;s:503:"a:4:{i:0;C:27:"Acme\UserBundle\Entity\User":166:{a:9:{i:0;s:8:"ZKkyZy84";i:1;s:31:"2bhrsabaoh7okoc8cc8cg0o4swccc0c";i:2;s:17:"10201664509493403";i:3;s:17:"10201664509493403";i:4;b:0;i:5;b:0;i:6;b:0;i:7;b:1;i:8;i:1;}}i:1;b:1;i:2;a:2:{i:0;O:41:"Symfony\Component\Security\Core\Role\Role":1:{s:47:"�Symfony\Component\Security\Core\Role\Role�role";s:10:"ROLE_ADMIN";}i:1;O:41:"Symfony\Component\Security\Core\Role\Role":1:{s:47:"�Symfony\Component\Security\Core\Role\Role�role";s:9:"ROLE_USER";}}i:3;a:0:{}}";}}' (length=1181)
'_csrf/sonata.batch' => string 't0FJ67l9S_2fn1YA-zlspeorTBvr0f7FRyZSjBJedFs' (length=43)
'flashes' =>
object(Symfony\Component\HttpFoundation\Session\Flash\FlashBag)[436]
private 'name' => string 'flashes' (length=7)
private 'flashes' => &
array (size=0)
empty
private 'storageKey' => string '_sf2_flashes' (length=12)
protected 'started' => boolean true
protected 'closed' => boolean false
protected 'saveHandler' =>
object(Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy)[432]
protected 'handler' =>
object(Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler)[56]
protected 'wrapper' => boolean true
protected 'active' => boolean true
protected 'saveHandlerName' => string 'files' (length=5)
protected 'metadataBag' =>
object(Symfony\Component\HttpFoundation\Session\Storage\MetadataBag)[55]
private 'name' => string '__metadata' (length=10)
private 'storageKey' => string '_sf2_meta' (length=9)
protected 'meta' => &
array (size=3)
'u' => int 1436891357
'c' => int 1436891127
'l' => string '0' (length=1)
private 'lastUsed' => int 1436891143
private 'updateThreshold' => string '0' (length=1)
private 'flashName' => string 'flashes' (length=7)
private 'attributeName' => string 'attributes' (length=10)
protected 'locale' => string 'en' (length=2)
protected 'defaultLocale' => string 'en' (length=2)