社区,在同一页面上接收相同模型“发布”的条目的多个表存在问题。单击分页器编号时,应用程序将更改两个表的页面。
我在 AppModel 中使用虚拟类进行了尝试,它应该可以工作,但我收到一条错误消息,指出发生了内部错误(错误 500)。我发现相应的 SQL 语句存在问题,未找到行。
在应用模型中:
class PostHood extends Post {
public $useTable = 'posts';
};
该代码使用“class Post extends AppModel”的表“cake_posts”。在控制器中,我尝试获取 PostHood,如下所示:
$this->paginate['PostHood'] = array(
'conditions' => array('OR' => array(stuff)),
'limit' => 5
);
$this->set('postsHood', $this->paginate('PostHood'));
在视图中有一个使用 $postsHood 作为 $post 的 foreach 循环。也许你有一个想法,在此先感谢:)
编辑1:更改代码后我收到了一些错误通知。可能你知道该怎么做。AppModel的变化:
class PostHood extends AppModel {
var $name = 'Post';
public $useTable = 'posts';
};
控制器:
$this->loadModel('PostHood');
$this->paginate = array(
'conditions' => array('OR' =>
array(
array('AND' => array(
array('PostHood.ZIPCODE LIKE' => $userArea . '%'),
array('PostHood.ALTDATE >' => date("Y-m-d")),
array('PostHood.AGENT' => '0'),
array('PostHood.OWNER <>' => $this->UserAuth->getUserId()),
array('PostHood.PARENTID' => '0'),
array('PostHood.ACCEPTED' => '0')
)), [MORE AND ARRAYS]
$this->set('postsHood', $this->paginate('PostHood'));
视图中对应的错误:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Post.DATE' in 'order clause'
SQL 查询:选择PostHood
。id
, PostHood
. B/S
, PostHood
. H
, PostHood
. CITY
,
PostHood
. MARKET
, PostHood
. DATE
, PostHood
. ALTDATE
, PostHood
. TIME
, PostHood
. INCOME
, PostHood
. ZIPCODE
, PostHood
. ALIAS
, PostHood
. VEHICLE
, PostHood
. DELIVERYAREA
, PostHood
. SPACE
, PostHood
. STREET
, PostHood
. HOUSENUMBER
, PostHood
. NAME
, PostHood
. CART
, PostHood
. TEL
, PostHood
. OWNER
, PostHood
. created
, PostHood
. modified
, PostHood
. AGENT
, PostHood
. EXTRADATA
, PostHood
. PARENTID
, PostHood
. BRATED
, PostHood
. SRATED
, PostHood
. REQUESTED
, PostHood
.ACCEPTED
从usr_web126986_4
。cake_posts
AS PostHood
WHERE 1 = 1 ORDER BY Post
。DATE
上升限制 5
显然,Cake 尝试使用“PostHood”获取数据,但我真正想要使用的表“posts”正在收听“Post.field”。我该如何解决?谢谢 :)