Sunday, January 3, 2010

Re: Problem with app_controller.php

This is a code on app_controller file:

<?php
class AppController extends Controller {

var $helpers = array('Html', 'Form', 'Recording', 'Taggable');
var $components = array('Session', 'Redirect');

function searchConditions($params = null){
$conditions = array();
$statuses = array('published' => '1', 'drafts' => '2');
if(isset($params['named']['q'])){
$conditions['MATCH(Post.title, Post.body) AGAINST(? IN
BOOLEAN MODE)'] = $params['named']['q'];
}
if(isset($params['named']['status']) && isset($statuses[$params
['named']['status']])){
$conditions['Post.status_id'] = $statuses[$params['named']
['status']];
}
return $conditions;
}
}
?>

and this is a posts_controller file:

<?php
class PostsController extends AppController {

var $name = 'Posts';

function admin_index(){
$this->Redirect->urlToNamed();
$this->pageTitle = 'Posts';
$conditions = $this->searchConditions($this->params);
<--- this line isn't work ;/
$this->Post->recursive = 0;
$this->set('posts', $this->paginate(), $conditions);
}

function admin_view($id = null){
$this->Redirect->idEmpty($id, array('action' => 'index'));
$post = $this->_findPost($id);
$this->pageTitle = $post['Post']['title'];
$this->set(compact('post'));
}

function admin_add(){
$this->pageTitle = 'Nowy Post';
if(!empty($this->data)){
$this->Post->create();
if($this->Post->save($this->data)){
$this->Redirect->flashSuccess('Posta zostal zapisany',
array('action' => 'view', $this->Post->id));
}
else{
$this->Redirect->flashWarning('Post nie moze zostac
zapisany');
}
}
$this-> _lists();
}

function admin_edit($id = null){
$this->Redirect->idEmpty($id, array('action' => 'index'));
$post = $this->_findPost($id);
$this-> pageTitle = 'Edytuj '.$post['Post']['title'];

if(!empty ($this->data)){
if($this->Post->save($this->data)){
$this->Redirect->flashSuccess('Posta zostal zapisany',
array('action' => 'view', $this->Post->id));
}
else{
$this->Redirect->flashWarning('Post nie moze zostac
zapisany');
}
}
if(empty ($this->data)){
$this->data = $post;
}
$this-> _lists();
}

function admin_delete($id = null){
$this->Redirect->idEmpty($id, array('action' => 'index'));
if($this->Post->del($id)){
$this->Redirect->flashSuccess('Post zostal usuniety', array
('action' => 'index'));
}
}

#Protected

function _findPost($id = null){
$post = $this->Post->find('first', array('conditions' => array
('Post.id =' => $id)));
if(empty($post)){
$this->Redirect->flashWarning('Post nie zostal
znaleziony', array('action' => 'index'));
}
return $post;
}

function _lists() {
$statuses = $this->Post->Status->find('list');
$this->set(compact('statuses'));
}
}
?>
Thank for help ;]

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: