2
votes

I am using Cakephp 1.3 As i have multiple controllers

like , Score, Stundets etc..

in score i have multiple functions with differents conditions Now what i need i want to add some logic in before filter function that to show only field is_deleted =0

I am trying this code

$this->Score->Student->conditions='Student.is_deleted=>0';

As passing all conditions too all function is too time Consuming

This above code is not working. I want to add filter So i will work in whole project

Anybody have an idea

Thanks

1

1 Answers

0
votes

You should use beforeFind() method in your Student model instead of putting your conditions logic in beforeFilter() method.

Write this code into Student Model:

function beforeFind($queryData)
{
    if (!isset($queryData['conditions'])) {
        $queryData['conditions'] = array();
    }       
    $queryData['conditions'][$this->alias.'.is_deleted'] = '0';       
    return $queryData;
}

This post might also help you to achieve the same.

You can also use Behavior Callbacks.

Hope it will work for you.