我有几个表格看起来像这个原型:
<tr><td><input type="text" name="directorios_url[]" value="" /></td>
<td><input type="text" name="directorios_kword[]" value="" /></td>
<td><input type="text" name="directorios_link[]" value="" /></td></tr>
问题是,当我尝试检索它们以在我的映射器中使用它时,我似乎只获得每行第三个的值:
protected '_directorios' =>
array
0 => string 'www.test.com/dir' (length=16)
protected '_rssFeeds' =>
array
0 => string 'www.test.com/rss' (length=16)
etc...
现在我正在mapper中使用一个名为setOptions的函数,如下所示:
public function setOptions(array $options) {
$methods = get_class_methods($this);
foreach ($options as $key => $value) {
//test
if(preg_match("/[a-zA-Z]_/", $key)){
$key = substr($key, 0, strpos($key.'_', '_') );
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}else{
//
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}
}
return $this;
}
关于如何以
的形式获取这些数组的任何想法protected '_directorios' =>
array
'directorios_url'
array( 0 => 'something.com',
1 => 'something2.com'),
array
'directorios_kword'
array( 0 => 'blah',
1 => 'blah'),
array
'directorios_link'
array( 0 => 'www.test.com/dir',
1 => 'www.test2.com/dir')
编辑:有关更多信息,此模型的setter和getter共享以下形式:
public function setDirectorios($directorios) {
$this->_directorios = (array) $directorios;
return $this;
}
public function getDirectorios() {
return $this->_directorios;
}