Hallo Im versuchen, eine Beiträge Abschnitte für ein Universitätsprojekt auf Video-Streaming-Website zu machen. Ich habe eine Posts Controller und Modell. Ich dachte, dass ich ein Element für das Posteingangskästchen erstellen würde, so dass ich dies in dem Abschnitt localhost/evolvids/uploads/watch/wiedergeben könnte, aber wenn ich einen Beitrag abschicke, bekomme ich einen MISSING CONTROLLER-Fehler.CakePHP Elements nicht aktualisiert Tabelle
Dies ist mein Code für die Beiträge Element
<div class="postsform">
<table>
<tr>
<td>
<?php echo $this->Form->create('Posts', array('action'=>'add'));
echo $this->Form->input('comment', array('between'=>'<br/>', 'cols'=>'60'));
echo $this->Form->input('video.id', array('id'=>'video_id','value' => $uploads['Upload']['id']));
echo $this->Form->input('user.id', array('id'=>'userid','value' => $auth['username']));
echo $this->Form->end(__('Submit', true));?>
</td>
</tr>
</table>
</div>
Das ist meine Beiträge Controller-Skript
<?php
class PostsController extends AppController {
var $name = 'Posts';
function index(){
$this->Post->recursive = 0;
$this->set('posts', $this->paginate());
}
function add(){
if (!empty($this->data)){
$this->Post->create();
if($this->Post->save($this->data)){
$this->Session->setFlash(__('Post saved', true));
} else{
$this->Session->setFlash(__('Post could not be saved. Please try again', true));
}
}
}
function view($id = null){
}
}
?>
Beiträge Modell
<?php
class Post extends AppModel{
public $name = 'Post';
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'id'
),
'Uploads' => array(
'className' => 'Uploads',
'foreignKey' => 'upload_id'
)
);
}
?>
Uploads-Controller
<?php
class UploadsController extends AppController {
var $name = 'Uploads';
public $components = array(
'Session',
'Auth'=>array(
'loginRedirect'=>array('controller'=>'uploads', 'action'=>'add'),
'logoutRedirect'=>array('controller'=>'users', 'action'=>'login'),
'authError'=>"Members Area Only, Please Login…",
'authorize'=>array('Controller')
)
);
public function isAuthorized($user) {
// regular user can access the file uploads area
if (isset($user['role']) && $user['role'] === 'regular') {
return true;
}
// Default deny
return false;
}
function browse ($id = null) {
$this->Upload->id = $id;
$this->set('uploads', $this->Upload->find('all'));
}
function watch ($id = null){
$this->Upload->id = $id;
$this->set('uploads', $this->Upload->read());
}
function add() {
if (!empty($this->data)) {
$this->Upload->create();
if ($this->uploadFile() && $this->Upload->save($this->data)) {
$this->Session->setFlash(__('<p class="uploadflash">The upload has been saved</p>', true));
$this->redirect(array('action' => 'add'));
} else {
$this->Session->setFlash(__('<p class="uploadflash">The upload could not be saved. Please, try again.</p>', true));
}
}
}
function uploadFile() {
$file = $this->request->data['Upload']['file'];
if ($file['error'] === UPLOAD_ERR_OK) {
$this->Upload->save($this->data); // data must be saved first before renaming to ID $this->(ModelName)->id
if (move_uploaded_file($file['tmp_name'], APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4')) {
return true;
}
}
return false;
}
}
?> Uploads Modell
<?php
class Upload extends AppModel {
public $name = 'Upload';
public $hasandBelongstoMany = array(
'User' => array(
'className' => 'User',
'unique' => 'true'),
'Posts' => array(
'className' => 'Posts',
'foreignKey' => 'id',
'associationForeignKey' => 'upload_id',
'associationForeignKey' => 'username',
'unique' => 'true')
);
}
?>
Auf den Uploads ansehen Ich rufe das Element wie folgt
<?php echo $this->element('Posts/add'); ?>
Irgendwelche Ideen, wo ich falsch gehe?
Ich habe jetzt folgende Fehlermeldung: Datenbankfehler Fehler: SQLSTATE [23000]: Integritätseinschränkungsverletzung: 1452 Hinzufügen oder Aktualisieren einer untergeordneten Zeile nicht möglich: Eine Fremdschlüsseleinschränkung schlägt fehl ('evolvids2'.posts', CONSTRAINT 'posts_ibfk_1' FREMDSCHLÜSSEL (' upload_id') REFERENZEN 'uploads' (' id') ON UPDATE CASCADE) SQL-Abfrage: INSERT INTO 'evolvids2'.posts' (' Kommentar') VALUES ('dsgsdg') – 001221
Die Abfrage fügt auch nicht den Benutzernamen und Uploadid in die Posts-Tabelle: S – 001221
auch wenn ich den Controller in das Plugin unter der app/plugins/posts AddController PostsAppController extends ich bekomme diesen Fehler geworfen Fataler Fehler: Klasse 'PostsAppController' nicht gefunden in/Anwendungen/XAMPP/xamppfiles/htdocs/evolvids/app/P lugin/Posts/Controller/AddController.php on line 4 – 001221