У меня возникает ряд ошибок, связанных с параметром profile_address. Большинство этого текущего кода пришли из рабочего обновления для 1 значения, с тех пор я пытался добавить обновление второго значения, и я хотел бы расширить его, чтобы обновить еще 10 значений.Как обновить несколько полей?
Я думаю, что проблема заключается в том, что переменные не обрабатываются правильно в моем приложении.
Первоначально я попытался добавить его в массив, как показано на модели, однако это не сработало.
Я думаю, что это довольно тривиальная проблема, и я уверен, что это простое решение, о котором я еще не думал.
Вид:
<form action="<?php echo Config::get('URL'); ?>login/editUserProfile_action" method="post">
<label for="comment">Name</label>
<textarea class="form-control" rows="3" name="profile_name"></textarea>
<br>
<label for="comment">Address</label>
<textarea class="form-control" rows="3" name="profile_address"></textarea>
</form>
Контроллер:
public function editUserProfile()
{
Auth::checkAuthentication();
$this->View->render('login/editUserProfile');
}
/**
* Edit user profile (perform the real action after form has been submitted)
* Auth::checkAuthentication() makes sure that only logged in users can use this action and see this page
*/
// make this POST
public function editUserProfile_action()
{
Auth::checkAuthentication();
UserModel::editUserProfile(Request::post('profile_name', 'profile_address'));
Redirect::to('login/editUserProfile');
}
Модель:
public static function editUserProfile($profile_name, $profile_address)
{
// write to database, if successful ...
if (UserModel::saveUserProfile(Session::get('user_id'), $profile_name, $profile_address)) {
Session::set(array('profile_name', $profile_name, 'profile_address', $profile_address));
Session::add('feedback_positive', Text::get('FEEDBACK_EMAIL_CHANGE_SUCCESSFUL'));
return true;
}
Session::add('feedback_negative', Text::get('FEEDBACK_UNKNOWN_ERROR'));
return false;
}
/**
* Writes new data to database
*
* @param $user_id int user id
*
* @return bool
*/
public static function saveUserProfile($user_id, $profile_name, $profile_address)
{
$database = DatabaseFactory::getFactory()->getConnection();
$query = $database->prepare("UPDATE users SET profile_name = :profile_name, profile_address = :profile_address WHERE user_id = :user_id LIMIT 1");
$query->execute(array(':profile_name' => $profile_name, ':profile_address' => $profile_address, ':user_id' => $user_id));
$count = $query->rowCount();
if ($count == 1) {
return true;
}
return false;
}
Не могли бы вы показать, где вы застряли? –
@NarendraSisodia Примером ошибки, которую я получаю, является: Неопределенная переменная: profile_address в C: \ wamp \ www \ application \ model \ UserModel.php в строке 358 – hylian
Пожалуйста, прекратите использование процедурной парадигмы программирования и изучите основы ООП. –