Hallo,
ich möchte schonmal vorab klären, dass ich mit cake gerade angefangen hab.
Folgendes Problem.
Ich habe mich an das Standard-Blog-Tutorial gehalten und bin gerade dabei, jedem Post ein Kategorie zu verpassen.
Die Ausgabe sieht so aus.
img3.imageshack.us/img3/2861/localhostcakeposts.png
Was ich will sind die Kategoriennamen.
Der PostView
Alles anzeigen
Der PostController
Alles anzeigen
CatController
Alles anzeigen
CatModdel
Alles anzeigen
PostModdel
Alles anzeigen
Zudem würde ich auch gerne wissen wie ich den Select von der Kategorie validieren kann.
gruß
ich möchte schonmal vorab klären, dass ich mit cake gerade angefangen hab.
Folgendes Problem.
Ich habe mich an das Standard-Blog-Tutorial gehalten und bin gerade dabei, jedem Post ein Kategorie zu verpassen.
Die Ausgabe sieht so aus.
img3.imageshack.us/img3/2861/localhostcakeposts.png
Was ich will sind die Kategoriennamen.
Der PostView
Quellcode
- <h1>Mein erstes Blog</h1>
- <?php echo $html->link('Post hinzufügen',array('controller' => 'posts', 'action' => 'add'))?>
- <table>
- <tr>
- <th>Titel</th>
- <th>Inhalt</th>
- <th>Erstellt</th>
- <th>Löschen</th>
- <th>Kategorie</th>
- </tr>
- <!– Hier wird nun eine Schleife eingefügt, die das $posts Array abarbeitet und pro Array-Zeile eine Tabellenzeile ausgibt –>
- <?php foreach($posts as $post):?>
- <tr>
- <td><?php echo $html->link($post["Post"]["titel"], "/posts/view/".$post["Post"]["id"]);?></td>
- <td><?php echo $post["Post"]["inhalt"];?></td>
- <td><?php echo $post["Post"]["created"];?></td>
- <td>
- <?php echo $html->link('Delete', array('action' => 'delete', $post['Post']['id']), null, 'Are you sure?' )?>
- <?php echo $html->link('Edit', array('action'=>'edit', $post['Post']['id']));?>
- </td>
- <td><?php echo $post["Post"]["category_id"];?></td>
- </tr>
- <?php endforeach;?>
- </table>
Der PostController
Quellcode
- <?php
- class PostsController extends AppController
- {
- var $name = "Posts";
- function index() {
- $eintraege = $this->Post->find('all');
- $this->set("posts",$eintraege);
- }
- function view($id = NULL) {
- $this->Post->id = $id;
- $this->set("post",$this->Post->read());
- }
- function add() {
- $categories = $this->Post->Category->getCategories();
- $this->set("cat", $categories);
- if (!empty($this->data)) {
- if ($this->Post->save($this->data)) {
- $this->Session->setFlash("Der Beitrag wurde erfolgreich gespeichert");
- $this->redirect("/posts");
- } else $this->Session->setFlash("Fehler");
- }
- }
- function delete($id) {
- $this->Post->delete($id);
- $this->Session->setFlash('The post with id: '.$id.' has been deleted.');
- $this->redirect(array('action'=>'index'));
- }
- function edit($id = null) {
- $this->Post->id = $id;
- if (empty($this->data)) {
- $this->data = $this->Post->read();
- } else {
- if ($this->Post->save($this->data)) {
- $this->Session->setFlash('Your post has been updated.');
- $this->redirect(array('action' => 'index'));
- }
- }
- }
- }
- ?>
CatController
Quellcode
CatModdel
Quellcode
PostModdel
Quellcode
Zudem würde ich auch gerne wissen wie ich den Select von der Kategorie validieren kann.
gruß