SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Netherlands
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CakePHP 1.2 paginate..

    Does anybody know how to define the fields with 1.2 paginate.. I have a HABTM on a tags table, and i get 30 queries on 15 results

    Controller
    PHP Code:
    class ArticlesController extends AppController
    {
        
    // Name
        
    var $name 'Articles';

        
    // Pagination settings
        
    var $paginate = array('limit' => 15'page' => 1);

        
    // Helpers
        
    var $helpers = array('Html','Form''Time''Ajax');    
        
        
    // Components used in controller
        
    var $components = array('Autocomplete'); 
        
        
    // Load other models
        
    var $uses = array('Tag''Menu''Article','Category');


        
    /**
         * This function shows a list of all articles
         * it will be called on /article or /article/index
         *
         */
        
    function index()
        {
               
    $this->set('articles',  $this->paginate('Article'));
        }


    Model:

    PHP Code:
    <?php
    class Article extends AppModel
    {
        
    // Model name
        
    var $name 'Article';

        
    // Database table
        
    var $useTable 'articles';

        
    // Use sef url's
        
    var $actsAs = array('Slug');
        
        
    // Validator
        
    var $validate = array(
        
    'title' => array('rule' => array('between'3255)),
        
    'article' => VALID_NOT_EMPTY
        
    );

        var 
    $hasAndBelongsToMany = array(
        
    'Tag' =>
            array(
    'className'    => 'Tag',
            
    'joinTable'    => 'articles_tags',
            
    'foreignKey'   => 'article_id',
            
    'associationForeignKey'=> 'tag_id',
            
    'conditions'   => '',
            
    'order'        => '',
            
    'limit'        => '',
            
    'unique'       => true,
            
    'finderQuery'  => '',
            
    'deleteQuery'  => '',
            ),
        
    'Category' =>
            array(
    'className'    => 'Category',
            
    'joinTable'    => 'articles_categories',
            
    'foreignKey'   => 'article_id',
            
    'associationForeignKey'=> 'category_id',
            
    'conditions'   => '',
            
    'order'        => '',
            
    'limit'        => '',
            
    'unique'       => true,
            
    'finderQuery'  => '',
            
    'deleteQuery'  => '',
            ),
        );

    }
    View:

    PHP Code:
    <h1>Articles</h1>
    <?php echo $html->link('New article''add');?>
    <table>
        <tr>
            <th>Id</th>
            <th>Title</th>
            <th>Edit</th>
            <th>Delete</th>        
            <th>Created</th>
            <th>Modified</th>        
        </tr>

       <!-- Here's where we loop through our $posts array, printing out post info -->

        <?php foreach ($articles as $article): ?>
        <tr>
            <td><?php echo $article['Article']['id']; ?></td>
            <td><?php echo $html->link($article['Article']['title'], "/articles/view/".$article['Article']['slug']); ?></td>
            <td><?php echo $html->link(
                    
    'Edit',
                    
    "/articles/edit/{$article['Article']['id']}")?>
            </td>        
            <td><?php echo $html->link(
                    
    'Delete',
                    
    "/articles/delete/{$article['Article']['id']}",
                    
    null,
                    
    'Are you sure?'
                
    )?>
            </td>
            <td><?php echo $time->timeAgoInWords(strtotime($article['Article']['created'])); ?></td>
            <td><?php echo $time->timeAgoInWords(strtotime($article['Article']['modified'])); ?></td>
        </tr>
        <?php endforeach; ?>

    </table>
    <?php echo $paginator->prev(); ?>
    <?php 
    echo $paginator->numbers(); ?>
    <?php 
    echo $paginator->next(); ?>
    Here are the queries it's make..

    Code:
    1DESCRIBE `cms_tags`
    224 2DESCRIBE `cms_menu`
    334 3DESCRIBE `cms_articles`
    774 4DESCRIBE `cms_categories`
    339 5SELECT COUNT(*) AS count FROM `cms_articles` AS `Article`   WHERE 1 = 1  
    1111 6SELECT `Article`.`id`, `Article`.`title`, `Article`.`slug`, `Article`.`article`, `Article`.`menu_id`, `Article`.`created`, `Article`.`modified` FROM `cms_articles` AS `Article` WHERE 1 = 1 LIMIT 15
    15151 7SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 2 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    0021 8SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 3 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    006 9SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 4 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    002 10SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 5 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 11SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 6 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 12SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 7 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 13SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 8 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 14SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 9 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 15SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 10 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 16SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 11 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 17SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 12 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 18SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 13 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 19SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 14 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 20SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 15 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 21SELECT `Tag`.`id`, `Tag`.`tag` FROM `cms_tags` AS `Tag` JOIN `cms_articles_tags` ON (`cms_articles_tags`.`article_id` = 16 AND `cms_articles_tags`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 
    000 22SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 2 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    002 23SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 3 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 24SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 4 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 25SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 5 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 26SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 6 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 27SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 7 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 28SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 8 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 29SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 9 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 30SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 10 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 31SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 11 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 32SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 12 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 33SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 13 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 34SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 14 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 35SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 15 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000 36SELECT `Category`.`id`, `Category`.`parent_id`, `Category`.`name` FROM `cms_categories` AS `Category` JOIN `cms_articles_categories` ON (`cms_articles_categories`.`article_id` = 16 AND `cms_articles_categories`.`category_id` = `Category`.`id`) WHERE 1 = 1 
    000
    Go visit my site :-D you know you want to ;-)
    www.mech7.net

  2. #2
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Netherlands
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nobody knows...
    Go visit my site :-D you know you want to ;-)
    www.mech7.net


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •