我正在为我的投资组合网站创建一个CMS项目.我无法使更新功能正常工作.我觉得它与我构建PDO事务的方式有关.在我的数据库中,我有一个项目表,类别表和关联的content_category表.我能够很好地将我的项目插入到这些表中.我想要做的是插入我的项目表然后删除content_category表中的所有记录,最后将当前类别记录插入到该关联表中以完成事务.我确实得到了返回声明"Project Updated".但表格没有更新.任何人的想法?
这是代码:
这是我的Project类中的一个函数.
public function update(){
try {
$conn = getConnection();
$conn->beginTransaction();
$sql = "UPDATE project
SET project_title = :title,
project_description = :desc,
project_isFeatured = :feat,
project_mainImage = :image
WHERE project_id = :id";
$st = $conn->prepare($sql);
$st->bindValue(":id", $this->id, PDO::PARAM_INT);
$st->bindValue(":title", $this->title, PDO::PARAM_STR);
$st->bindValue(":desc", $this->description, PDO::PARAM_STR);
$st->bindValue(":feat", $this->isFeatured, PDO::PARAM_BOOL);
$st->bindValue(":image", $this->mainImage, PDO::PARAM_INT);
$st->execute();
$sql = "DELETE from content_category
WHERE content_id = :id";
$st = $conn->prepare($sql);
$st->bindValue("id", $this->id, PDO::PARAM_INT);
$st->execute();
$sql = "INSERT into content_category (content_id, cat_id)
VALUES (?,?)";
$st = …Run Code Online (Sandbox Code Playgroud) 我正在尝试用Laravel实现分页,我的分页链接在网页上显示为原始html.我对Laravel很新,我不确定我哪里出错了.我正在使用Laravel 5.
UserController的@指数:
public function index()
{
$page = \Input::get('page', 1);
$data = $this->user->getByPage($page, 10);
$users = Pagination::makeLengthAware($data->items, $data->totalItems, 10 );
return view('admin.users.index', compact('users'));
}
Run Code Online (Sandbox Code Playgroud)
EloquentUser getByPage方法:
public function getByPage($page=1, $limit=10)
{
$result = new \StdClass;
$result->page = $page;
$result->limit = $limit;
$result->totalItems = 0;
$result->items = [];
$users = $this->user->skip($limit * ($page - 1))
->take($limit)
->get();
$result->totalItems = $this->user->count();
$result->items = $users->all();
return $result;
}
Run Code Online (Sandbox Code Playgroud)
分页服务:
<?php namespace App\Services;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
abstract class Pagination
{
/**
* …Run Code Online (Sandbox Code Playgroud)