Cakephp - Banner Problem
- by Joe Elliott
Hi guys
I have a banner rotator on my main page and it was working but it has stopped. All I have done before it stopped was modified some of the db fields. I added to fields position and company and deleted the field 'description.'
It was a friend of a friend that made this part of the site for me while i was on holiday so i dont know which files i should show you cos dont know exactly what hes done but im guessing the following ones are the ones you need.
banner_view
<div id="banner">
<?php
if(!empty($banners) && ($banners['Banner']['position']=='Top')){
foreach($banners as $banner){
?>
<a href="<?php echo $banner['Banner']['url']; ?>"><img src="<?php echo $banner['Banner']['path']; ?>" alt="<?php echo $banner['Banner']['company']; ?>" /></a>
<?php
}
}
?>
</div>
banner_controller
<?php
class BannersController extends AppController {
var $name = 'Banners';
var $helpers = array('Html', 'Form', 'Ajax','Javascript');
var $layout = 'ajax';
var $components = array('Session', 'Cookie');
function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow('index','featrot');
if(strpos($this->here, 'admin'))
{
$this->layout = 'admin';
}
}
function index() {
Configure::write('debug',0);
$this->Banner->recursive = 0;
$this->paginate['Banner'];
$banners = $this->paginate();
if($banners)
{
$this->set('banners', $banners);
}
}
function featrot() {
Configure::write('debug',0);
$this->Banner->recursive = 0;
$this->paginate['Banner'];
$banners = $this->paginate();
if($banners)
{
$this->set('banners', $banners);
}
}
function admin_edit(){
$this->pageTitle='Admin section - .: Banners Edit:.';
$banners = $this->Banner->find('first');
$id = $banners['Banner']['id'];
if (!empty($this->data)) {
$this->Banner->id = $id;
if ($this->Banner->save($this->data)) {
$this->Session->setFlash(__('The Banner has been updated', true));
} else {
$this->Session->setFlash(__('The Banner could not update. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Banner->read(null, $id);
}
}
function admin_display_banners($id=null){
$this->pageTitle='Admin section - .: Banners Setting :.';
if (!empty($this->data)) {
$this->Banner->id = $id;
if ($this->Banner->save($this->data)) {
$this->Session->setFlash(__("Banner#$id has been updated", true));
$this->Banner->id = null;
} else {
$this->Session->setFlash(__("Banner#$id could not update. Please, try again.", true));
}
}
$this->data = null;
$this->Banner->recursive = -1;
$this->paginate['Banner'];
$banners = $this->paginate('Banner');
$this->set('banners', $banners);
}
}
?>
banner_model
<?php
class Banner extends AppModel {
var $name = 'Banner';
}
?>
Hope this is all the details you need. Thanks in advance folks :)
Joe :)