我有一个要修改Joomla表单值的问题。当我点击Joomla保存按钮时,我首先要修改表单值,然后通过模型保存它。为此,我尝试在控制器中获取表单值,然后将该值传递给模型。值已成功打印为数组,但无法迭代该数组。
我在控制器中获取表单值的代码
public function save()
{
$app = JFactory::getApplication();
$model = $this->getModel('HelloWorld');
// Get the data from the form POST
$data = JRequest::get('post');
//var_dump($data); die();
// Now update the loaded data to the database via a function in the model
$res = $model->save($data);
return true;
}
然后将数据作为数组传递给这样的模型
public function save($data)
{
print_r($data);//it is bening printed successfully
echo 'Greeting: ' . $data['greeting'];//it is not being printed as I want to fetch
}
print_r($data)
显示的数组是这样的
Array ( [jform] => Array ( [id] => [greeting] => Hahaha ) [task] => helloworld.save [4f80fadfc470fa5addfe322aeb6256d6] => 1 )
所有我想迭代的数组并获得问候值,然后在修改后将其保存在数据库中