0

I have a HTML form on my CakePHP application that passes a variable that is usually over 30 characters long through to my new Symfony2 application. I'm able to pass the variable from the form to Symfony without issue. However, when I echo the variable that's been passed to Symfony the variable only seems to contain just the first character of the 30/40 character sequence.

The variable is usually like this: T2psbWFGWjNXbTRob3p0VGEwVENheVZvTVRSRFRVUnFLMDVmYVhnaU5ucFJNVWgzZVZSUlRXOXI=

The HTML form used by CakePHP is like this:

<form id="TestForm" method="POST" action="/web/app_dev.php/instructors/passport/" name="input">
<input type="text" value="UkVsS1JtMW1VRFZvT21raU1HVXJVQ3RaTVRSS2JVd3JWRjVxVEdnbVZEUkZiakZsV2pjemNVWTM=" name="value">
<input type="submit" value="Go to the New Database">
</form>

The Symfony2 code is like this:

public function passportAction(Request $request)
{
    $passport = $this->getRequest()->get("value");

    // Get variables from the search form
    $value = $passport['value'];

    $session = new Session();
    $session->start();

    $session->set('passport', $value);
    $sessionval = $session->get('passport');

    print_r($sessionval);

    return $this->render('DatabaseBundle:Default:test.html.twig', array(
        'pagename' => 'Database Does Not Exist',
        'branchname' => 'Test Branch',
        'group' => '0',
        'something' => $sessionval
    ));
}

With this code, and using that variable, in Symfony2 the only thing that is displayed when the variable is echoed is T. What is going on?

4

2 回答 2

1

Your bug comes from the fact that when you wrote :

$passport = $this->getRequest()->get("value");

$passport already contains your variable as a string, but a string is nothing more than a pseudo array of characters. Then, later on your code, you ask for $passport['value'] and php is not bothered that you use [] on a string because it thinks you are trying to access one character from the whole string. To finish, maybe the trickiest part, where I might be wrong on explaining. You are trying to access to the value pointed by 'value' key, in fact 'value' key does not exist but I think a cast is done by php here, and it is resolved as the value 0.

于 2013-07-30T10:06:59.730 回答
0

try this $this->getRequest()->get("TestForm")['value']

于 2013-07-30T10:09:46.917 回答