我确实谷歌但没有找到任何合适的解决方案来创建一个新的字段,如果不是字段。
例如:如果我必须根据任何其他语言的标题添加字段。
title
,title_eng
,title_fr
...等等
我在php
找到了解决方案,但正在寻找cakephp
$languageData = $this->LanguageSetting->find('first', array('conditions' => array('id' => $post['language_id'])));
$short_name = $languageData['LanguageSetting']['short_name'];
$subjectfieldName = "email_subject_" . $short_name;
$contentfieldName = "email_template_" . $short_name;
//add subject field if not present
$subjectfield = $this->LanguageSetting->query("SELECT $subjectfieldName FROM email_managers");
if (!$subjectfield) {
$insert_col = "ALTER TABLE email_managers ADD " . $subjectfieldName . " VARCHAR(255) NULL";
}
//add template field if not present
$contentfield = $this->LanguageSetting->query("SELECT $contentfieldName FROM email_managers");
if (!$contentfield) {
$insert_col = "ALTER TABLE email_managers ADD " . $contentfieldName . " TEXT NULL";
}
我尝试了以上解决方案,但收到了此错误。
数据库错误
错误:SQLSTATE [42S22]:找不到列:1054未知列 'field list'中的'email_subject_'
答案 0 :(得分:-1)
这可能会对你有所帮助。
$columns = $this->LanguageSetting->query('show columns from email_managers');
$exists = FALSE;
foreach ($columns as $fields) {
if ($fields['COLUMNS']['Field'] == $subjectfieldName) {
$exists = true;
break;
}
}
if (!$exists) {
$this->LanguageSetting->query("ALTER TABLE email_managers ADD " . $subjectfieldName . " VARCHAR(255) NULL");
}