0
我正在cakephp中第一次爲我正在開發的項目工作。在視圖中,我有一個數組,我希望能夠在其中使用控制器功能。從視圖發送信息到控制器
陣列我有信息在是這個
$linkedinInfo
然後在視圖我使用的形式從視圖陣列發送到控制器
$this->Form->create('LinkedinData', array('controller'=>'Users','type' => 'post', 'action' => 'add'));
$this->Form->input('User', $linkedinInfo);
$this->Form->end('submit');
添加是添加一個用戶控制器中的功能,這個功能並不是由我開發的。是
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}}
我收到錯誤「陣列字符串轉換」,在此,我不是很熟悉CakePHP的工作,但我不明白爲什麼我得到這個,因爲Cookboek函數使用一切都像我 http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
編輯:LinkedinInfo是,我通過LinkedIn API獲得一個數組,然後我向後編輯它。這裏的結構只是爲recomendations部分樣品
[linkedin_recomendations] => Array
(
[0] => Array
(
[name] => test1
[relationship] => education
[text] => Hello world
)
[1] => Array
(
[name] => test2
[relationship] => colleague
[text] => Derp
)
)
我所試圖做的是將這個信息發送到UsersController它會在MongoDB數據庫
你的整個表單都很搞砸了。在沒有'url => array()''的create()中,控制器鍵是無效的。此外,它的小寫'用戶'。您的輸入字段應該是'Modelname.field_name',並且只包含一個值(除非其某個下拉列表或多個字段)。 – mark 2013-04-30 17:40:16
你確定嗎?因爲我沒有看到url ==>「array」的例子。關於輸入字段,我的數組是一個多維數組,那麼這意味着我將不得不逐一放置每個字段? – user697110 2013-04-30 17:48:09
你究竟想達到什麼目的? 1)'$ linkedInInfod'的**內容**是什麼樣的? 2)'$ linkedInInfod'從哪裏來?它是否需要首先顯示在表單中,還是要在沒有其他用戶交互的情況下將其插入到數據庫中?請通過[編輯]鏈接 – thaJeztah 2013-04-30 17:49:23