How to echo Users' Comments for individual Events - cakephp

Hi all Iam using Cakephp 2.x, I need to output individual users' comments for each individual event. Each user has many events and many comments. I have Events, Comments and Users models and want to allow users to post and view comments on each event view.ctp. If anyone could give any starting tips to implement this functionality it would be much appreciated.
I have tried to output the comments model index table in the events view.ctp, but the table is not populated with the comments from the database, but the comments view.ctp does in fact populate the table with the comments. I have used the $this->loadModel('Comments'); function in the events controller.
<div class="events view">
<?php echo $this->Html->css('viewevent'); ?>
<?php echo $this->element('maintitlegen'); ?>
<div style="padding-top: 160px">
<h2><?php echo $event['Event']['name']; ?></h2>
<dl>
<dt><?php echo __('Event Image'); ?></dt>
<dd>
<?php echo $this->Html->image('/uploads/event/filename/thumb/small/'.$event['Event']['filename']); ?>
</dd>
<dt><?php echo __('Date'); ?></dt>
<dd>
<?php echo h($event['Event']['date']); ?>
</dd>
<dt><?php echo __('Time'); ?></dt>
<dd>
<?php echo h($event['Event']['time']); ?>
</dd>
<dt><?php echo __('Description'); ?></dt>
<dd>
<?php echo h($event['Event']['description']); ?>
</dd>
<dt><?php echo __('Dresscode'); ?></dt>
<dd>
<?php echo h($event['Event']['dresscode']); ?>
</dd>
<dt><?php echo __('Slogan'); ?></dt>
<dd>
<?php echo h($event['Event']['slogan']); ?>
</dd>
<dt><?php echo __('Price'); ?></dt>
<dd>
<?php echo h($event['Event']['price']); ?>
</dd>
<dt><?php echo __('Offers'); ?></dt>
<dd>
<?php echo h($event['Event']['offers']); ?>
</dd>
</dl>
<!--<?php foreach ($users as $user): ?>
<?php echo $user['Comment']['comment']; ?>
<?php endforeach; ?>-->
<!--<?php echo $ucomment['Comment']['comment']; ?>-->
<?php echo $this->Form->create('Comment', array('controller' => 'comments', 'action' => 'add')); ?>
<?php echo ('Add Comment'); ?>
<?php echo $this->Form->input('comment'); ?>
<?php echo $this->Form->end('Submit'); ?>
</div>
<div class="comments index">
<h2><?php echo ('Comments'); ?></h2>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('comment'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<th><?php echo $this->Paginator->sort('modified'); ?></th>
<th><?php echo $this->Paginator->sort('user_id'); ?></th>
<th><?php echo $this->Paginator->sort('event_id'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
<?php
foreach ($comments as $comment): ?>
<tr>
<td><?php echo h($comment['Comment']['id']); ?> </td>
<td><?php echo h($comment['Comment']['comment']); ?> </td>
<td><?php echo h($comment['Comment']['created']); ?> </td>
<td><?php echo h($comment['Comment']['modified']); ?> </td>
<td>
<?php echo $this->Html->link($comment['User']['name'], array('controller' => 'users', 'action' => 'view', $comment['User']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($comment['Event']['name'], array('controller' => 'events', 'action' => 'view', $comment['Event']['id'])); ?>
</td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $comment['Comment']['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $comment['Comment']['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $comment['Comment']['id']), null, __('Are you sure you want to delete # %s?', $comment['Comment']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<div class="paging">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
</div>
</div>
////////////////////////////////User model///////////////////////////////////////////////
<?php
class User extends AppModel {
public $name = 'User';
public $displayField = 'name';
public $validate = array(
'name'=>array(
'Please enter your name.'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter your name.'
)
),
'username'=>array(
'That username has already been taken'=>array(
'rule'=>'isUnique',
'message'=>'That username has already been taken.'
),
'Valid email'=>array(
'rule'=>array('email'),
'message'=>'Please enter a valid email address'
)
),
'email'=>array(
'Valid email'=>array(
'rule'=>array('email'),
'message'=>'Please enter a valid email address'
)
),
'password'=>array(
'Not empty'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter your password'
),
'Match passwords'=>array(
'rule'=>'matchPasswords',
'message'=>'Your passwords do not match'
)
),
'password_confirmation'=>array(
'Not empty'=>array(
'rule'=>'notEmpty',
'message'=>'Please confirm your password'
)
)
);
public function matchPasswords($data) {
if ($data['password'] == $this->data['User']['password_confirmation']) {
return true;
}
$this->invalidate('password_confirmation', 'Your passwords do not match');
return false;
}
public function beforeSave($options = array()) {
if (isset($this->data['User']['password'])) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
}
return true;
}
public $hasMany = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
public $hasOne = array(
'Profile' => array(
'className' => 'Profile',
'foreignKey' => 'user_id',
'dependent' => true));
var $actsAs = array(
'MeioUpload.MeioUpload' => array('filename'=>array(
'thumbsizes'=>array(
'small'=>array(
'width'=>'75',
'height'=>'75',
'forceAspectRatio'=>'C'
)))));
}
?>
///////////////////////////////////// Users Controller///////////////////////////////////
<?php
class UsersController extends AppController {
public $name = 'Users';
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
public function isAuthorized($user) {
if ($user['role'] == 'admin') {
return true;
}
// if (in_array($this->action, array('delete'))) {
// if ($user['id'] != $this->request->params['pass'][0]) {
// return false;
// }
// }
return true;
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Your username/password combination was incorrect');
}
}
}
// public function logout() {
// $this->redirect($this->Auth->logout());
// }
public function index() {
$this->User->recursive = 0;
$this->set('users', $this->User->find('all'));
}
public function view($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException('Invalid user');
}
if (!$id) {
$this->Session->setFlash('Invalid user');
$this->redirect(array('action' => 'index'));
}
$this->set('user', $this->User->read());
}
public function add() {
if ($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash('Now create your profile!');
$this->Auth->login();
$this->redirect(array('controller'=> 'profiles', 'action' => 'add'));
} else {
$this->Session->setFlash('Your account cannot be created. Please try again.');
}
}
// if (!empty($user)){
// $this->request->data['Profile']['user_id'] = $this->User->id;
// $this->User->Profile->save($this->request->data);
// }
}
public function edit($id = null) {
$this->User->id = $id;
$user = $this->User->read();
if($user['User']['id'] != $this->Auth->user('id')){
$this->redirect(array('controller' => 'events','action' => 'index'));
}
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->request->is('get')) {
$this->request->data = $user;
} else {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Your account has been updated'));
$this->redirect(array('controller' => 'events', 'action' => 'index'));
} else {
$this->Session->setFlash(__('Your account cannot be saved. Please try again.'));
}
}
}
public function delete($id = null) {
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if (!$id) {
$this->Session->setFlash('Invalid id for user');
$this->redirect(array('action'=>'index'));
}
if ($this->User->delete($id)) {
$this->Session->setFlash('User deleted');
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash('User was not deleted');
$this->redirect(array('action' => 'index'));
}
}
?>

I think it is safe to assume your comment table has at least the following columns:
id
user_id
event_id
comment (or name)
The view you display in the OP is the view for the events.view method. But you do not show the even model or controller. So I am not certain if you need help with the events controller or if you are trying to display event data in the users controller. The way to get all of the comments for the view you show in the OP is to pull all of the comments from the model like so:
$this->set('comments', $this->Event->Comment->find('all', array('conditions' => array('event_id' => $event_id))));
If you want the user data to be displayed along with it, you will need to either set recursive = 1 or write a join to join the user data.

Related

cakephp pagination controller

what shoud i write in the controller to have pagiation
this is my index
<?php foreach ($bien['Servicebien'] as $servicebien): ?>
<tr> <td><?php echo $servicebien['dateServiceBienDu']; ?>
<td><?php echo $servicebien['dateServiceBien']; ?></td>
<td><?php echo $servicebien['montantServiceBien']; ?></td>
</tr>
<?php endforeach; ?>
<?php unset($servicebien); ?>
</table>
<div>
<?php echo $this->Paginator->counter(array('format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}'))); ?>
Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
echo $this->Paginator->numbers();
echo $this->Paginator->next(' Next >> ', null, null, array('class' => 'disabled'));
?>
$data = $this->Paginator->paginate('model_name');
$this->set('data', $data);
Try this
class FeedsController extends AppController {
public $components = array( 'Search.Prg');
public function beforeFilter() {
parent::beforeFilter();
}
function indes(){
$this->Prg->commonProcess();
$this->{$this->modelClass}->data[$this->modelClass] = $this->passedArgs;
$parsedConditions = $this->{$this->modelClass}->parseCriteria($this->passedArgs);
$this->paginate = array(
'conditions' => array(),
'limit' => 10,
'fields' => array(),
'order' => 'id DESC'
);
$result = $this->paginate();
}
}

CakePHP-3.0 plugin form validation error message and entered data

I have created a CommentManager plugin for adding comments in my posts. Adding the comment form in Posts/view.ctp file and the comment form action is redirecting to CommentManager/Comments/add.
The comments are saving properly but when saving empty form, that doesn't shows the validation error messages which i have written in CommentsTable and also the entered data has gone from the form.
CommentManager/src/Controller/CommentsController/add
public function add()
{
$ccomment = $this->Comments->newEntity($this->request->data);
if ($this->request->is('post')) {
$newData = ['post_id' => $this->request->params['pass'][0]];
$ccomment = $this->Comments->patchEntity($ccomment, $newData);
if ($this->Comments->save($ccomment)) {
$this->Flash->success('The comment has been saved.');
return $this->redirect($_SERVER['HTTP_REFERER']);
} else {
$this->Flash->error('The comment could not be saved. Please, try again.');
}
}
$this->set(compact('ccomment'));
return $this->redirect($_SERVER['HTTP_REFERER']);
}
CommentManager/src/Model/Table/CommentsTable
public function validationDefault(Validator $validator) {
return $validator
->notEmpty('body', 'Body contents required.')
->notEmpty('email', 'An email is required.')
->add('email', [
'format' => [
'rule' => [
'custom',
'/^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
],
'message' => 'Enter a valid email.'
]
]);
}
src/Template/Posts/view.ctp
<?php echo $this->Html->link('Back', ['action' => 'index']) ?>
<?php echo $this->element('check_login'); ?>
<br/>
<?php $img_path = DS.'webroot'.DS.'images'.DS.$post->image; ?>
<img src="<?php echo empty($post->image)?'':$img_path; ?>">
<h2><?php echo $post->title; ?></h2>
<p><?php echo $post->body; ?></p>
<p><small><?php echo $post->created->format('d M Y'); ?></small></p>
<h3>Comments:</h3>
<?php foreach ($comments as $comment) { ?>
<p><?php echo $comment->body; ?></p>
<?php } ?>
<?php
echo $this->Form->create(null, ['url' => ['plugin' => 'CommentManager', 'controller' => 'Comments', 'action' => 'add', $post->id]]);
echo $this->Form->input('body', ['type' => 'textarea', 'rows' => '5', 'cols' => '5']);
echo $this->Form->input('email');
echo $this->Form->button('Save');
echo $this->Form->end();
?>
Don't call newEntity() with an empty array. Inste of
$ccomment = $this->Comments->newEntity($this->request->data);
Do:
$ccomment = $this->Comments->newEntity();
And in in the call to patchEntity() pass the $this->request->data

cakephp 2x pagination of a different model

I'm trying to paginate Workers which belong(s)To Job within a JobsController.
class JobsController extends AppController {
var $name = 'Jobs';
var $helpers = array('Html', 'Form', 'Js');
var $paginate = array(
'Worker' => array(
'limit' => 5,
'recursive' => 0,
'model' => 'Worker',
'order' => array('age' => 'ASC')
),
);
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Job.'));
$this->redirect(array('action'=>'index'));
return;
}
$this->Job->id = $id;
$workers = $this->paginate('Worker', array('Worker.job_id' => $id));
if ($workers) {
$this->set('workers', $workers);
}
}
In view.ctp:
<?php
$this->Html->script(array('jquery.min'), array('inline' => false));
$this->Paginator->options(array(
'update' => '#content',
'evalScripts' => true,
));
?>
<?php if (isset($workers)): ?>
<?php echo $this->Paginator->numbers(array('model' => 'Worker')); ?>
<table>
<tr>
<th>Age</th>
<th>Info</th>
</tr>
<?php foreach ($workers as $worker): ?>
<tr>
<td>
<?php echo $worker['Worker']['age']; ?>
</td>
<td>
<?php echo $worker['Worker']['info']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $this->Paginator->numbers(array('model' => 'Worker')); ?>
<p>
<?php
echo $this->Paginator->counter(array(
'model' => 'Worker',
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total.')
));
?></p>
<?php endif; ?>
<?php echo $this->Js->writeBuffer(); ?>
I'm getting the correct list of workers. But the links generated by numbers are not working. They look like /view/2/page:2/sort:Worker.age/direction:ASC
What am I doing wrong? cakephp version is 2.4.1.
Try this in your view action, by setting the order at run time.
$this->paginate['Worker']['order'] = array('Worker.age' => 'ASC')
Now your function look like this
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Job.'));
$this->redirect(array('action'=>'index'));
return;
}
$this->Job->id = $id;
$this->paginate['Worker']['order'] = array('Worker.age' => 'ASC');
$workers = $this->paginate('Worker', array('Worker.job_id' => $id));
if ($workers) {
$this->set('workers', $workers);
}
}
Hope this helps you.

Cakephp Model error

I am facing a strange problem while creating edit functionality in cakephp 2.1
Error genreated:
Illegal offset type [CORE\Cake\Model\Model.php, line 2689]
My edit.ctp file is
<?php echo $this->Form->create('Task');?>
<fieldset>
<legend>Edit Task</legend>
<?php
echo $this->Form->hidden('id');
echo $this->Form->input('title');
echo $this->Form->input('done');
?>
</fieldset>
<?php echo $this->Form->end('Save');?>
Model: Task.php
<?php
class Task extends AppModel {
var $name = 'Task';
}
?>
Controller :TasksController.php
<?php
class TasksController extends AppController {
var $name = 'Tasks';
var $helpers = array('Html', 'Form');
function index() {
$this->set('tasks', $this->Task->find('all'));
}
function add() {
if (!empty($this->data)) {
$this->Task->create();
if($this->Task->save($this->data)){
$this->Session->setFlash('The Task has been saved');
$this->redirect(array('action'=>'index'),null,true);
}else{
$this->Session->setFlash('Task not saved.Try again.');
}
}
}
function edit($id = null) {
if (!$id) {
$this->Session->setFlash('Invalid Task');
$this->redirect(array('action' => 'index'), null, true);
}
if (empty($this->data)) {
$this->data = $this->Task->find(array('id' => $id));
} else {
if ($this->Task->save($this->data)) {
$this->Session->setFlash('The Task has been saved');
$this->redirect(array('action' => 'index'), null, true);
} else {
$this->Session->setFlash('The Task could not be saved.Please, try again.');
}
}
}
}
?>
I think your find() method is erroneous:
$this->data = $this->Task->find(array('id' => $id));
change to
$this->data = $this->Task->find('all', array('conditions' => array('id' => $id)));
http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
In order to prepopulate the data on the form you need to do the following:
<?php echo $this->Form->create('Task');?>
<fieldset>
<legend>Edit Task</legend>
<?php
echo $this->Form->hidden('id', array('value' => $this->data[0]['Task']['id']));
echo $this->Form->input('title', array('value' => $this->data[0]['Task']['title']));
echo $this->Form->input('done', array('value' => $this->data[0]['Task']['done']));
//var_dump($this->data[0]['Task']['id']);
?>
</fieldset>
<?php echo $this->Form->end('Save');?>
<?php echo $this->Html->link('List All Tasks', array('action'=>'index')); ?><br />
<?php echo $this->Html->link('Add Task', array('action'=>'add')); ?><br />
<?php echo $this->Html->link('List Done Tasks', array('action'=>'index')); ?><br />
<?php echo $this->Html->link('List Pending Tasks', array('action'=>'index')); ?><br />

cakephp: search page giving http 404 webpage cannot be found

When I click the search link in the cupcake forum plugin, enter the search criteria and click submit, I get a blank page in firefox and http 404 website cannot be found in IE.
I have no idea on what i'm doing wrong. Can someone help me? Thank you.
the following is the search_controller:
class SearchController extends ForumAppController {
/**
* Controller Name
* #access public
* #var string
*/
public $name = 'Search';
/**
* Models
* #access public
* #var array
*/
public $uses = array('Forum.Topic');
/**
* Pagination
* #access public
* #var array
*/
public $paginate = array(
'Topic' => array(
'order' => 'LastPost.created DESC',
'contain' => array('ForumCategory.title', 'User.id', 'User.username', 'LastPost.created', 'LastUser.username', 'Poll.id', 'FirstPost.content')
)
);
/**
* Search the topics
* #access public
* #param string $type
*/
public function index($type = '') {
$searching = false;
print_r($this->params['named']);
// Build
if (!empty($this->params['named'])) {
foreach ($this->params['named'] as $field => $value) {
$this->data['Topic'][$field] = urldecode($value);
}
}
if ($type == 'new_posts') {
$this->data['Topic']['orderBy'] = 'LastPost.created';
$this->paginate['Topic']['conditions']['LastPost.created >='] = $this->Session->read('Forum.lastVisit');
}
echo '<br/>';
print_r($this->data);
// Search
if (!empty($this->data)) {
$searching = true;
$this->paginate['Topic']['limit'] = $this->Toolbar->settings['topics_per_page'];
if (!empty($this->data['Topic']['keywords'])) {
if ($this->data['Topic']['power'] == 0) {
$this->paginate['Topic']['conditions']['Topic.title LIKE'] = '%'. $this->data['Topic']['keywords'] .'%';
} else {
$this->paginate['Topic']['conditions']['OR'] = array(
array('Topic.title LIKE' => '%'. $this->data['Topic']['keywords'] .'%'),
array('FirstPost.content LIKE' => '%'. $this->data['Topic']['keywords'] .'%')
);
}
}
if (!empty($this->data['Topic']['category'])) {
$this->paginate['Topic']['conditions']['Topic.forum_category_id'] = $this->data['Topic']['category'];
}
if (!empty($this->data['Topic']['orderBy'])) {
$this->paginate['Topic']['order'] = $this->data['Topic']['orderBy'] .' DESC';
}
if (!empty($this->data['Topic']['byUser'])) {
$this->paginate['Topic']['conditions']['User.username LIKE'] = '%'. $this->data['Topic']['byUser'] .'%';
}
$this->set('topics', $this->paginate('Topic'));
}
$this->Toolbar->pageTitle(__d('forum', 'Search', true));
$this->set('menuTab', 'search');
$this->set('searching', $searching);
$this->set('forums', $this->Topic->ForumCategory->getHierarchy($this->Toolbar->getAccess(), $this->Session->read('Forum.access'), 'read'));
}
}
?>
topic.php model:
class Topic extends ForumAppModel {
/**
* Belongs to
* #access public
* #var array
*/
public $belongsTo = array(
'ForumCategory' => array(
'className' => 'Forum.ForumCategory',
'counterCache' => true
),
'User' => array(
'className' => 'Forum.User'
),
'FirstPost' => array(
'className' => 'Forum.Post',
'foreignKey' => 'firstPost_id'
),
'LastPost' => array(
'className' => 'Forum.Post',
'foreignKey' => 'lastPost_id'
),
'LastUser' => array(
'className' => 'Forum.User',
'foreignKey' => 'lastUser_id'
)
);
/**
* Has one
* #access public
* #var array
*/
public $hasOne = array(
'Poll' => array(
'className' => 'Forum.Poll',
'dependent' => true
)
);
/**
* Has many
* #access public
* #var array
*/
public $hasMany = array(
'Post' => array(
'className' => 'Forum.Post',
'exclusive' => true,
'dependent' => true,
'order' => 'Post.created DESC',
)
);
index.ctp view:
<?php // Search orderbY
$orderBy = array(
'LastPost.created' => __d('forum', 'Last post time', true),
'Topic.created' => __d('forum', 'Topic created time', true),
'Topic.post_count' => __d('forum', 'Total posts', true),
'Topic.view_count' => __d('forum', 'Total views', true)
); ?>
<h2>Search</h2>
<?php echo $form->create('Topic', array('url' => array('controller' => 'search', 'action' => 'index'))); ?>
<div id="search">
<?php
echo $form->input('keywords', array('div' => false, 'label' => false, 'style' => 'width: 300px'));
echo $form->label('power', __d('forum', 'Power Search?', true));
echo $form->input('category', array('div' => false, 'label' => false, 'options' => $forums, 'escape' => false, 'empty' => true));
echo $form->input('orderBy', array('div' => false, 'label' => false, 'options' => $orderBy));
echo $form->label('byUser', __d('forum', 'By User (Username)', true) .':');
echo $form->input('byUser', array('div' => false, 'label' => false, 'style' => 'width: 150px'));
?>
</div>
<?php echo $form->end(__d('forum', 'Search Topics', true));
pr($this->validationErrors);
?>
<?php // Is searching
if ($searching === true) { ?>
<div class="forumWrap">
<?php echo $this->element('pagination'); ?>
<table cellspacing="0" class="table">
<tr>
<th colspan="2"><?php echo $paginator->sort(__d('forum', 'Topic', true), 'Topic.title'); ?></th>
<th><?php echo $paginator->sort(__d('forum', 'Forum', true), 'Topic.forum_category_id'); ?></th>
<th><?php echo $paginator->sort(__d('forum', 'Author', true), 'User.username'); ?></th>
<th><?php echo $paginator->sort(__d('forum', 'Created', true), 'Topic.created'); ?></th>
<th><?php echo $paginator->sort(__d('forum', 'Posts', true), 'Topic.post_count'); ?></th>
<th><?php echo $paginator->sort(__d('forum', 'Views', true), 'Topic.view_count'); ?></th>
<th><?php echo $paginator->sort(__d('forum', 'Activity', true), 'LastPost.created'); ?></th>
</tr>
<?php if (empty($topics)) { ?>
<tr>
<td colspan="8" class="empty"><?php __d('forum', 'No results were found, please refine your search criteria.'); ?></td>
</tr>
<?php } else {
$counter = 0;
foreach ($topics as $topic) {
$pages = $cupcake->topicPages($topic['Topic']); ?>
<tr<?php if ($counter % 2) echo ' class="altRow"'; ?>>
<td class="ac" style="width: 35px"><?php echo $cupcake->topicIcon($topic); ?></td>
<td>
<?php if (!empty($topic['Poll']['id'])) {
echo $html->image('/forum/img/poll.png', array('alt' => 'Poll', 'class' => 'img'));
} ?>
<?php echo $cupcake->topicType($topic['Topic']['type']); ?>
<strong><?php echo $html->link($topic['Topic']['title'], array('controller' => 'topics', 'action' => 'view', $topic['Topic']['id'])); ?></strong>
<?php if (count($pages) > 1) { ?>
<br /><span class="gray"><?php __d('forum', 'Pages'); ?>: [ <?php echo implode(', ', $pages); ?> ]</span>
<?php } ?>
</td>
<td class="ac"><?php echo $html->link($topic['ForumCategory']['title'], array('controller' => 'categories', 'action' => 'view', $topic['Topic']['forum_category_id'])); ?></td>
<td class="ac"><?php echo $html->link($topic['User']['username'], array('controller' => 'users', 'action' => 'profile', $topic['User']['id'])); ?></td>
<td class="ac"><?php echo $time->niceShort($topic['Topic']['created'], $cupcake->timezone()); ?></td>
<td class="ac"><?php echo number_format($topic['Topic']['post_count']); ?></td>
<td class="ac"><?php echo number_format($topic['Topic']['view_count']); ?></td>
<td>
<?php // Last activity
if (!empty($topic['LastPost'])) {
$lastTime = (!empty($topic['LastPost']['created'])) ? $topic['LastPost']['created'] : $topic['Topic']['modified']; ?>
<em><?php echo $time->relativeTime($lastTime, array('userOffset' => $cupcake->timezone())); ?></em><br />
<span class="gray"><?php __d('forum', 'by'); ?> <?php echo $html->link($topic['LastUser']['username'], array('controller' => 'users', 'action' => 'profile', $topic['Topic']['lastUser_id'])); ?></span>
<?php echo $html->image('/forum/img/goto.png', array('alt' => '', 'url' => array('controller' => 'topics', 'action' => 'view', $topic['Topic']['id'], 'page' => $topic['Topic']['page_count'], '#' => 'post_'. $topic['Topic']['lastPost_id']))); ?>
<?php } else {
__d('forum', 'No latest activity to display');
} ?>
</td>
</tr>
<?php ++$counter;
}
} ?>
</table>
<?php echo $this->element('pagination'); ?>
</div>
<?php } ?>
I added:
if (isset($this->Security)){
$this->Security->enabled=false;
}
to the beforeFilter function of search_controller.php and i'm able to get the search results now. No more HTTP 404 website not found error. :)

Resources