Creer un post et ajouter catégories
Voici tout d'abord le schéma de ma BDD, mon schéma yml se trouve tout en bas au cas ou.
http://img41.imageshack.us/img41/9355/bdd.png
Pour le besoin de faire des tests simples j'essaye de créer un post et de lui ajouter des catégories.
Code:
1 2 3 4 5 6 7 8
|
$post1 = new Post(); //création d'un post
$post1->body = 'post avec deux catégories cat1 et cat2';
//Jusque la tout va bien le post est bien créé avec le bon body.
//ajouter des catégories à un post.
$post1->save(); |
J'ai essayé pleins de trucs pour ajouter des catégories mais je ne sais vraiment pas comment m'y prendre, il doit me manquer encore cette logique symfony.
Merci pour votre éventuelle aide.
Mon yml.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| Post:
actAs:
Sluggable:
unique: true
fields: [title]
canUpdate: true
notnull: true
columns:
id:
type: integer(8)
primary: true
notnull: true
autoincrement: true
author_user_id:
type: integer(8)
notnull: true
title:
type: string(256)
notnull: true
excerpt:
type: clob
body:
type: clob
notnull: true
#publish, pending, future, trash, ne pas pouvoir effacer un post tant qu'il n'est pas en mode trash
post_status:
type: string(16)
notnull: true
comment_status:
type: boolean
notnull: true
default: 1
ActAsnb_comment:
type: integer(8)
notnull: true
default: 0
relations:
postAuthor:
class: sfGuardUser
local: author_user_id
foreign: id
type: one
foreignType: many
foreignAlias: Posts
options:
charset: armscii8
collate: armscii8_bin
Category:
columns:
id:
type: integer(8)
primary: true
notnull: true
autoincrement: true
name:
type: string(32)
notnull: true
ActasSlug:
type: string(45)
notnull: true
description:
type: clob
parent:
type: integer(8)
notnull: true
default: 0
count:
type: integer(4)
notnull: true
default: 0
options:
charset: utf8
collate: utf8_unicode_ci
PostCategory:
columns:
post_id:
type: integer(8)
primary: true
notnull: true
cat_id:
type: integer(8)
primary: true
notnull: true
relations:
post:
class: Post
local: post_id
foreign: id
foreignAlias: PostCategories
cat:
class: Category
local: cat_id
foreign: id
foreignAlias: PostCategories
options:
charset: utf8
collate: utf8_unicode_ci |