久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CakePHP 表單選擇值作為 table.id,選擇選項文本作為

CakePHP form select value as table.id, select option text as table.textfield(CakePHP 表單選擇值作為 table.id,選擇選項文本作為 table.textfield)
本文介紹了CakePHP 表單選擇值作為 table.id,選擇選項文本作為 table.textfield的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我是 Cake 的新手.我已經設置了一些東西,相關的用戶"和配置文件"表、控制器、模型和視圖.在我的 profiles/add 視圖中,我試圖輸出一個 select 輸入,其值為 user.id 并且選項文本為user.username.最終,值 user.id 將保存在 profile.user_id 中.

I'm new to Cake. I've gotten some things set up, relevantly a "users" and a "profiles" table, controller, model and view. In my profiles/add view, I'm attempting to output a select input with the value being the user.id and the option text being the user.username. Ultimately, the value user.id will be saved in profile.user_id.

我已經閱讀了大量文檔,并成功設置了 select 以輸出 user 表中的選項,但它使用了 user.id 作為值和選項文本.

I have read through a lot of documentation, and successfully set up the select to output the options from the user tables, but it uses the user.id as both the value and the option text.

控制器:

    $this->set('users', $this->Profile->User->find('list'));

查看:

    echo $this->Form->input('user_id');

這種事情似乎是例行公事,所以如果我完全忽略了它,請隨意回答文檔的鏈接.

It seems like this sort of thing would be routine, so feel free to answer with just a link to the documentation if I've overlooked it completely.

謝謝!

推薦答案

成功設置選擇以從用戶表中輸出選項,但它使用 user.id 作為值和選項文本.

successfully set up the select to output the options from the user tables, but it uses the user.id as both the value and the option text.

find('list') 默認使用主鍵作為鍵,模型的 displayField 作為值.

find('list') will by default use the primary key as the key, and the model's displayField as the value.

如果一個模型沒有明確的displayField但是有一個名為titlename的字段,Cake會自動選擇這個字段,否則不會猜測并簡單地使用主鍵字段 - 這就是問題中發生的事情.

If a model does not have an explicit displayField but has a field named title or name Cake will automatically pick this field, otherwise it will not guess and simply use the primary-key field - which is what's happening in the question.

然而,您可以簡單地在 find('list') 調用的結果中指定您想要的字段.因此,要么:

You can however simply specify which fields you want in the results of your find('list') call. Therefore either:

class User extends AppModel {

    public $displayField = 'username';

}

然后使用:

$users = $this->User->find('list');

顯式選擇字段

$users = $this->User->find('list', array(
    'fields' => array('id', 'username')
));

在這兩種情況下 - 結果都是例如:

In both cases - the result will be e.g.:

array(
    1 => 'firstuser',
    ...
    76 => 'AD7six'
)

這篇關于CakePHP 表單選擇值作為 table.id,選擇選項文本作為 table.textfield的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 久久国产亚洲 | 97人人澡人人爽91综合色 | 91精品免费视频 | 国产一区二区三区四区区 | 亚洲 欧美 在线 一区 | 国产在线91| 亚洲一级二级三级 | 美女逼网站 | 狠狠涩 | 91久久北条麻妃一区二区三区 | 久久视频免费观看 | 一道本一区二区 | 亚洲国产精品99久久久久久久久 | 亚洲精选一区二区 | 二区在线观看 | julia中文字幕久久一区二区 | 久久精品亚洲一区二区三区浴池 | 亚洲欧美日韩在线一区二区 | 91欧美精品成人综合在线观看 | 久久人人爽人人爽人人片av免费 | 中文字幕视频在线观看免费 | 亚洲bt 欧美bt 日本bt | 精品久久久久久亚洲精品 | 91视视频在线观看入口直接观看 | 成人网在线观看 | 欧美1区 | 欧美一区二不卡视频 | 日韩欧美高清 | 亚洲综合三区 | 国产一区二区久久 | 高清av在线 | 91影院在线观看 | 日韩电影中文字幕 | 91福利电影在线观看 | 毛片久久久 | 亚洲精品3 | 日韩在线中文 | 久久国产精品一区二区 | 国产91精品网站 | 免费黄视频网站 | 日日碰狠狠躁久久躁婷婷 |