本文整理汇总了PHP中Mapper::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Mapper::save方法的具体用法?PHP Mapper::save怎么用?PHP Mapper::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper::save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
function save(Feed $feed)
{
parent::save($feed);
foreach ($feed->items() as $item) {
$item->feed_id($feed->id());
$item->save();
}
}
示例2: index
function index()
{
if (!empty($_POST)) {
$check = new Check();
if (!empty($_FILES["img"]["name"])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
$filename = $check->checkInput($_FILES['img']['name']);
$filesize = filesize($target_file);
move_uploaded_file($_FILES["img"]["tmp_name"], $target_file);
} else {
$filename = '';
$filesize = '';
}
//Получаем данные методом пост
$name = $check->checkInput($_POST['name']);
$surname = $check->checkInput($_POST['surname']);
$email = $check->checkInput($_POST['email']);
$login = $check->checkInput($_POST['login']);
$pass = $check->checkInput($_POST['pass']);
$confirmpass = $check->checkInput($_POST['confirmpass']);
$age = $check->checkInput($_POST['age']);
//Создаем массив для валидации данных
$validateArr = array('name' => $name, 'surname' => $surname, 'email' => $email, 'login' => $login, 'password' => $pass, 'confirmpass' => $confirmpass, 'age' => $age, 'filename' => $filename, 'filesize' => $filesize);
$pdo = new Db();
//класс с конфигурацией базы данных
$db = $pdo->get();
$validate = new Validate($db);
$errors = $validate->getErrors($validateArr);
//Выявляем ошибки через валидатор
if (empty($errors)) {
try {
//Сохраняем пользователя посредством паттерна Data Mapper
$user = new User();
$user->name = $name;
$user->surname = $surname;
$user->email = $email;
$user->login = $login;
$user->password = md5($pass);
$user->age = $age;
$user->filename = $filename;
$mapper = new Mapper($db);
$mapper->save($user);
$this->user = $mapper->select($user);
$this->out('profile.php');
} catch (Exception $e) {
echo "Ошибка загрузки данных <br>" . $e->getMessage();
}
} else {
foreach ($errors as $error) {
$this->error = $error . "<br>";
}
$this->out('register.php');
}
} else {
$this->out('register.php');
}
}
示例3: log
public static function log($message)
{
$logEntry = new \Bh\Entity\LogEntry($message);
Mapper::save($logEntry);
Mapper::commit();
}
示例4: function
$app->get('/add', function () use($app) {
$main = '';
$add = 'active';
return $app['twig']->render('add.twig', array('main' => $main, 'add' => $add));
});
$app->post('/add', function () use($app) {
if (isset($_POST)) {
$check = new Check();
$name = $check->checkInput($_POST['name']);
$comment = $check->checkInput($_POST['comment']);
$pdo = new Db();
$db = $pdo->get();
$validate = new Validate($db);
$data = array('name' => $name, 'comment' => $comment);
$errors = $validate->getErrors($data);
if (!empty($errors)) {
$main = '';
$add = 'active';
return $app['twig']->render('add.twig', array('main' => $main, 'add' => $add, 'errors' => $errors, 'name' => $name, 'comment' => $comment));
} else {
$mapper = new Mapper($db);
$ip_address = $_SERVER['REMOTE_ADDR'];
$comments = new Comments();
$comments->name = $name;
$comments->comment = $comment;
$comments->ip_address = $ip_address;
$mapper->save($comments);
return $app->redirect('/GuestBook/');
}
}
});