Witam serdecznie,
mam jedno pytanko, nie wiem jak zrobić dodawanie zdjęć . Działa mi wyświetlanie i edycja. Jednak stoje na dodawaniu :(
components przestawia się następująco:
<?php class PhotosController extends AppController {
var $name = 'Photos';
var $uses = array('Photo', 'Person');
function admin_index() {
$photos = $this->Photo->find('all');
$this->set(compact('photos'));
}
function index() {
$photos = $this->Photo->find('all');
if (isset ($this->params['requested'])) {
return $photos;
}
$this->Photo->recursive = 0;
$this->set('photos', $this->paginate());
}
function admin_add(){
if (!empty($this->data)) {
$this->Photo->create();
if ($this->Photo->save($this->data)) {
$this->Session->setFlash('zdjecie zostalo dodane !', 'adflash', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('zdjecie nie zostalo dodane !', 'adflash', array('class' => 'error'));
}
}
$people = $this->Person->find('list');
$this->set(compact('people'));
}
}
?>
model:
- w tabeli Photos jest relacja do tabeli people
<?php
class Photo extends AppModel {
var $belongsTo = array(
'Person' => array(
'className' => 'Person',
'foreignKey' => 'person_id',
'conditions' => '',
'fields' => '',
'order' => ''
));
}
?>
view:
<h5> dodaj zdjecie </h5>
<label> nazwa ogloszenia: </label>
<?php
echo $this->Form->input('person_id', array('options' => $people, 'label' => false));
?>
<label> zdjecie: </label>
<?php
echo $this->Form->input('link', array('type' => 'file', 'div' => false, 'label' => false, 'id' => 'uploading', 'class' => 'validate[required]'));
?>
<input type="submit" value="dodaj" class="redBtn submitForm" />
po użyciu przycisku, powinna sie wyświetlić lista zdjęć:
<h5> zdjecia </h5>
<table>
<thead>
<tr>
<th> id </th>
<th> person_id </th>
<th> link </th>
<th> opcje </th>
</tr>
</thead>
<tbody>
<?php
foreach($photos as $photo) {
?>
<tr>
<td> <?php echo $photo['Photo']['id']; ?> </td>
<td> <?php echo $photo['Photo']['person_id']; ?> </td>
<td> <?php echo $html->image($photo['Photo']['link'], array('alt' => 'Gallery Image')); ?> </td>
<td>
<a href="<?php echo $this->Html->url(array('action' => 'edit', $photo['Photo']['id'])) ?>" title="" >
<span> edycja </span>
</a>
<a href="<?php echo $this->Html->url(array('action' => 'delete', $photo['Photo']['id'])) ?>" title="" >
<span> usun </span>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
proszę uprzejmie o wskazówkę , wydaje mi sie ze jest cos tu nie tak:
echo $this->Form->input('link', array('type' => 'file', 'div' => false, 'label' => false, 'id' => 'uploading', 'class' => 'validate[required]'));