浏览代码

Introduction Models

Model
Ruben De Baets 2 年前
父节点
当前提交
34f891f763
共有 4 个文件被更改,包括 86 次插入6 次删除
  1. 8
    5
      public/index.php
  2. 2
    1
      src/DB/Blog.php
  3. 58
    0
      src/Model/Blog.php
  4. 18
    0
      src/Model/Comment.php

+ 8
- 5
public/index.php 查看文件

@@ -11,15 +11,18 @@ use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Blog\DB\User;
use Blog\DB\Blog;
use Blog\DB\Blog as BlogDB;
use Blog\View\Twig;
use Blog\DB\DB;

use Blog\Model\Blog;


require __DIR__ . '/../vendor/autoload.php';



#addNavbar();

$container = new Container();
AppFactory::setContainer($container);
@@ -41,9 +44,9 @@ $container->set(
);


function addNavbar()
function addNavbar($twig)
{
$twig = $this->get('twig');
//$twig = $this->get('twig');

$urls = [
["link" => "https://www.google.be", "name" => "Google"],
@@ -82,7 +85,7 @@ $app->get('/', function (Request $request, Response $response, array $args) {
];

$twig = $this->get('twig');
addNavbar($twig);
$err = ['type' => 'error', 'text' => "something's wrong"];

$twig->addMessage($err);

+ 2
- 1
src/DB/Blog.php 查看文件

@@ -2,10 +2,11 @@

namespace Blog\DB;

use Blog\Model\Blog as BlogModel;

class Blog extends DB
{
public function createBlog($data)
public function createBlog(BlogModel $data)
{
$this->enableExceptions(false);
$stmt = $this->prepare("INSERT INTO blogs (slug, title, content) VALUES (:slug, :title, :content)");

+ 58
- 0
src/Model/Blog.php 查看文件

@@ -0,0 +1,58 @@
<?php

namespace Blog\Model;


use Blog\DB\Blog as BlogDB;
use Blog\Model\Comment;

class Blog
{
protected $author;
protected $title;
protected $subtitle;
protected $date;
protected $content;
protected $comments;
protected $id;
protected $slug;

public function setAuthor($value)
{
$this->author = $value;
}

public function setDate($value)
{
$this->date = $value;
}

public function getDate()
{
return $this->date;
}

public function getAuthor()
{
return $this->author;
}

public function getComments()
{
$comments = new Comment();
$this->comments = $comments->getComments($this->id);
return $this->comments;
}

public function save()
{
$db = new BlogDB();
$data = ["slug" => $this->slug, "title" => $this->title, "content" => $this->content];
//$db->createBlog($data);
$db->createBlog($this);
}

public function getAssociative()
{
}
}

+ 18
- 0
src/Model/Comment.php 查看文件

@@ -0,0 +1,18 @@
<?php

namespace Blog\Model;

class Comment
{

protected $user;
protected $date;
protected $blogID;
protected $comment;

public function getComments($blogID)
{
// vraag de DB om alle comments voro blogID
return [];
}
}

正在加载...
取消
保存