开发者

Retrieve some Array data from a Submit form in cakePHP

I am learning cakePHP 1.26.

I got a HTML Select tag with some o开发者_开发问答ptions like this:

<form method="post" action="/testing">  
<table border="1">  
<tr>    
<td>
<select name="data[Test][number]">  
<option name="editquote" value="[29,1]">One</option>    
<option name="editquote" value="[24,2]">Two</option>    
</select>   
</td>   
<tr>    
<td>    
<input type="submit" value="Send" class="mybutton"> 
</td>   
</tr>   
</table>    
</form> 

I selected option One and submitted the form.

Here is the result from the cakePHP built-in function, Debug()

Array
(
    [Test] => Array
        (
            [number] => [29,1]
        )

)

I tried using the following code to get the two numbers from the data (i.e. 29 and 1 in this example) but failed to do it

$myData=$this->data;
$myData['Test']['number'];  // [29, 1]

What should I do to get the two numbers separately?


You could try this with PHP explode.

$numbers = explode(',', trim($myData['Test']['number'], '[]'));
$numbers[0]; //29
$numbers[1]; //1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜