Недавно я создавал компонент загрузки для back-end joomla 3.1. на основе How to Save Uploaded File's Name on Database Мне удалось переместить файл на жесткий диск, однако я просто не могу получить запрос на обновление для работы на основе опубликованного сообщения выше.Joomla 3.1 Запрос на обновление базы данных не работает
У меня нет ошибок SQL и сохранения, но почему-то игнорирует часть базы данных.
Я действительно надеюсь, что пропустил что-то очевидное. (Кстати, я не знаю, как JOOMLA запросов очень хорошо)
В phpmyadmin
следующий запрос работает:
UPDATE hmdq7_mysites_projects
SET project_file = 'test'
WHERE id IN (3);
Я попытался следующие запросы:
$id = JRequest::getVar('id');
$db =& JFactory::getDBO();
$sql = "UPDATE hmdq7_mysites_projects
SET project_file =' " . $filename. "'
WHERE id IN (".$id.");";
$db->setQuery($sql);
$db->query();
$colum = "project_file";
$id = JRequest::getVar('id');
$data = JRequest::getVar('jform', null, 'post', 'array');
$data['project_file'] = strtolower($file['name']['project_file']);
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__mysites_projects');
$query->set($column.' = '.$db->quote($data));
$query->where('id'.'='.$db->quote($id));
$db->setQuery($query);
$db->query();
Введите текущий код:
class MysitesControllerProject extends JControllerForm
{
function __construct() {
$this->view_list = 'projects';
parent::__construct();
}
function save(){
// ---------------------------- Uploading the file ---------------------
// Neccesary libraries and variables
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
$path= JPATH_SITE . DS . "images";
// Create the gonewsleter folder if not exists in images folder
if (!JFolder::exists(JPATH_SITE . "/images" )) {
JFactory::getApplication()->enqueueMessage($path , 'blue');
}
// Get the file data array from the request.
$file = JRequest::getVar('jform', null, 'files', 'array');
// Make the file name safe.
$filename = JFile::makeSafe($file['name']['project_file']);
// Move the uploaded file into a permanent location.
if ($filename != '') {
// Make sure that the full file path is safe.
$filepath = JPath::clean(JPATH_SITE . "/images/" . $filename);
// Move the uploaded file.
JFile::upload($file['tmp_name']['project_file'], $filepath);
$colum = "project_file";
$id = JRequest::getVar('id');
$data = JRequest::getVar('jform', null, 'post', 'array');
$data['project_file'] = strtolower($file['name']['project_file']);
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__mysites_projects');
$query->set($column.' = '.$db->quote($data));
$query->where('id'.'='.$db->quote($id));
$db->setQuery($query);
$db->query();
}
// ---------------------------- File Upload Ends ------------------------
JRequest::setVar('jform', $data);
return parent::save();
}
Решено: после рассмотрения сообщения http://stackoverflow.com/questions/14531603/update-record-in-database-using-jdatabase?rq=1. Я составил некоторые фиксированные значения теста. получается, что запрос правильный, но переменная $ data в запросе не имела данных. $ data ['project_file'] = strtolower ($ file ['name'] ['project_file']); удалил массив из первой части и обработанной переменной. – user2617187