回显一个表在不同索引页面上的结果cakephp

时间:2016-07-25 21:46:28

标签: php cakephp cakephp-3.x

我目前在文章index.ctp中回应了计数查询的结果。现在我想从同一篇文章index.ctp上的类别表中回显相同的查询,以便它们出现在同一页面上。有关如何做到这一点的任何建议吗?

文章管理员:

public $uses = array('Articles', 'Categories');

public function index()
{


    $this->paginate = [
    'contain'=>['Categories']
    ];
    $articles = $this->paginate($this->Articles);
    $this->set('articles', $this->Articles->find('all'));
    $this->set(compact('articles'));
    $this->set('_serialize', ['articles']);

    $article_count = $this->Articles->find('all')->count();
    $this->set('article_count',$article_count );

    $author_count = $this->Articles->find('all')
        ->distinct(['Articles.user_id'])
        ->count('user_id');
    $this->set('author_count',$author_count );

    $category_count = $this->Categories->find('all')->count();
    $this->set('category_count',$category_count );
}

文章index.ctp:

<div class="col-xs-12 col-md-6 col-lg-3 widget">
        <div class="panel panel-red panel-widget">
            <div class="row no-padding">
                <div class="col-sm-3 col-lg-5 widget-left">
                    <svg class="glyph stroked app-window-with-content"><use xlink:href="#stroked-app-window-with-content"></use></svg>
                </div>
                <div class="col-sm-9 col-lg-7 widget-right">
                    <div class="large"><?php echo $category_count; ?></div>
                    <div class="text-muted">Categories</div>
                </div>
            </div>
        </div>
    </div>

非常感谢任何帮助。

由于

2 个答案:

答案 0 :(得分:0)

结果是loadModel函数允许你这样做

import pygame, sys
import random
from pygame import *

pygame.init()

red = (255, 0, 0)
white = (255, 255, 255)
black = (0, 0, 0)
blue = (0, 0, 255)
green = (0, 255, 0)

screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("flap it up")
clock = pygame.time.Clock()
MAX_VEL = 5
GAP = 175
WALLSPEED = -2
WALLEVENT = pygame.USEREVENT+1
SCOREEVENT = pygame.USEREVENT+2
pygame.time.set_timer(WALLEVENT, 5000)
pygame.time.set_timer(SCOREEVENT, 2500)
myfont = pygame.font.SysFont("monospace", 18)

class Player(object):
    def __init__(self):
        self.rect = pygame.Rect(384, 284, 32, 32)
        self.xvel = 0
        self.yvel = MAX_VEL
        self.xcel = 0
        self.ycel = 1

    def move(self):
        self.rect.top += self.yvel
        if self.yvel < MAX_VEL:
            self.yvel += self.ycel
        else:
            self.yvel = MAX_VEL


    def jump(self):
        self.yvel = -15

    def draw(self):
        pygame.draw.rect(screen, red, self.rect)


class Wall(object):
    def __init__(self, y):
        self.rect1 = pygame.Rect(800, y, 32, 600-y)
        self.rect2 = pygame.Rect(800, 0, 32, y-GAP)
        self.xvel = WALLSPEED

    def move(self, walls):
        self.rect1.x += self.xvel
        self.rect2.x += self.xvel
        if self.rect1.x < -31:
            walls.remove(self)

    def draw(self):
        pygame.draw.rect(screen, green, self.rect1)
        pygame.draw.rect(screen, green, self.rect2)

class BG(object):
    def __init__(self, x):
        self.x = x
        self.xvel = WALLSPEED
        self.img = pygame.image.load("bg.jpg")

    def move(self, bg):
        self.x += self.xvel
        if self.x < -799:
            bg.remove(self)
            bg.append(BG(self.x+1600))
        screen.blit(self.img, (self.x, 0))

def lose():
    pygame.quit()
    quit()

def main(player, walls, bg, score, playing):
    while playing:
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                player.jump()
            if event.type == WALLEVENT:
                numbo = random.randrange(GAP, 600, 25)
                walls.append(Wall(numbo))
            if event.type == SCOREEVENT:
                score += 1

        for b in bg:
            b.move(bg)

        label = myfont.render("Score: " + str(score), 1, (0, 0, 0))
        screen.blit(label, (30, 20))

        player.move()
        player.draw()
        for w in walls:
            w.move(walls)
            w.draw()
            if player.rect.colliderect(w.rect1) or player.rect.colliderect(w.rect2):
                lose()
                playing = False


        clock.tick(60)
        pygame.display.update()

player = Player()
walls = []
bg = []
score = 0
walls.append(Wall(300))
bg.append(BG(0))
bg.append(BG(800))
playing = True

main(player, walls, bg, score, playing)

答案 1 :(得分:0)

.error