Tencent / Biny

Biny is a tiny, high-performance PHP framework for web applications
BSD 3-Clause "New" or "Revised" License
1.69k stars 258 forks source link

问下TXEvent::one(onSql);这个方法为什么用不了,还有左联表相同字段数据覆盖问题 #68

Closed coolsharkll closed 6 years ago

coolsharkll commented 6 years ago

`<?php namespace app\controller;

class testAction extends baseAction { //默认路由index public function action_index() { $DAO = $this->modsDAO; TXEvent::one(onSql); $DAO = $DAO->leftJoin($this->mods_typeDAO,array('mods_type_id'=>'id'))->query();//左联接mods_type return $this->display('main/test', array('test'=>1), array('path'=>$DAO)); } }` ?> 报错如下: Fatal error: Autoload file[app\controller\TXEvent] is fails in D:\wamp64\www\biny\lib\TXAutoload.php:116 Stack trace:

0 [internal function]: biny\lib\TXAutoload::load('app\controller\...')

1 D:\wamp64\www\biny\app\controller\testAction.php(11): spl_autoload_call('app\controller\...')

2 [internal function]: app\controller\testAction->action_index()

3 D:\wamp64\www\biny\lib\business\TXController.php(69): call_user_func_array(Array, Array)

4 D:\wamp64\www\biny\lib\business\TXController.php(42): biny\lib\TXController->call(Object(biny\lib\TXRequest))

5 D:\wamp64\www\biny\lib\business\TXController.php(105): biny\lib\TXController->execute()

6 D:\wamp64\www\biny\lib\TXApp.php(177): biny\lib\TXController->dispatcher()

7 D:\wamp64\www\biny\web\index.php(21): TXApp::run()

8 {main}

主要在左联其他数据表的时候如果主表有和左联表有相同名称字段.比如两个表都有id字段.查询后输出的id为左联表的id,而不是主表的id.想看下sql调试结果发现也没法调试.

billge1205 commented 6 years ago

Biny 在2.7.2之后加入了命名空间 要使用TXEvent 需要调用 use biny\lib\TXEvent; 或者 直接写 \biny\lib\TXEvent::one(onSql);

billge1205 commented 6 years ago

关于联表中重复的字段可以在fields里指定输出时的变量名 例如 $filter->query([['id', 'name'], ['id'=>'newid', 'time'], '*']); 这里第二张表中的id就会转为newid,取表中所有数据用‘*’

coolsharkll commented 6 years ago

非常感谢