CakePHP 1.3获取所有与表相关的数据

时间:2018-09-28 10:11:36

标签: php cakephp cakephp-1.3

我有三个表user_loguserdesignation

在这里,我将记录user_log表中的所有记录,并且也应该显示designation->name。但user_logdesignation TABLE没有关系。只有user表具有designation->iduser_loguser->id

如何获取designation->nameuser_log数据,

user_loguser之间的关系

var $belongsTo = array(
    'loginUser' => array(
        'className' => 'User',
        'foreignKey' => 'user'

    )
);

This is what I have now as a data `array()`,


  Array
   (
     [0] => Array
    (
        [ActionLog] => Array
            (
                [id] => 1
                [action] => CommitteesController->delete
                [user] => 29
                [remark] => id-548
                [created] => 2018-09-27 14:21:32
                [status] => 1
            )

        [loginUser] => Array
            (
                [id] => 29
                [company_id] => 2
                [username] => admin
                [password] => 20b90f704be7df945d2ede3fac7fe29b1765f4ae
                [user_type] => 0
                [designation_id] => 5
                [name] => Super Admin user
                [address] => 
                [mobile_number] => 
                [email] => admin1@gmail.com
                [uuid] => 11cb016ea2cfa61161b6d85aa1e42f98c6a3829f
                [is_active] => 1
                [is_director] => 0
                [is_new_user] => 0
                [office_phone] => 
                [group_id] => 1
            )

    )

这就是我从控制器获取数据的方式

    function index(){
    $search = null;
    $dateRange  =null;
    if(!empty($_POST['search'])){
       $search = array('ActionLog.'.$_POST['column'].' LIKE' => '%'.$_POST['field'].'%');
        //IF DATE AVAILABLE
        if(!empty($_POST['startDate']) && !empty($_POST['endDate'])){
            $startDate = $_POST['startDate'];
            $endDate = $_POST['endDate'];
            $dateRange = array("ActionLog.created between ? and ?"=>array($startDate,$endDate));
            $search = array_merge($search,$dateRange);
        }
    }

    $this->paginate = array(
        'conditions' => $search,
        'limit' => 10
    );
    $data = $this->paginate('ActionLog');
    $this->set('logs', $data);
}

如何获取与designation相关的user数据?

0 个答案:

没有答案