Expecting a Baby Girl!

Posted: February 13th, 2010 | Author: admin | Filed under: Personal | 1 Comment »

My wife and I just got back from the clinic today. She took an ultrasound and we found out we are going to have a baby girl! My first born is a baby girl! Everything is right where it should be…I hope and pray she’ll come out healthy. I’m so happy today :-D


CakePHP sessions

Posted: February 9th, 2010 | Author: admin | Filed under: Javascript, PHP | No Comments »

If you are developing an CakePHP application where ajax is mostly used. It is advisable that you set the following session configurations inside your core.php.

Configure::write('Session.timeout', '86400'); // expires in 30 days

Configure::write('Security.level', 'medium');

If your application calls more than one ajax request at the same time, it is recommended that you set your ajax requests to synchronous to prevent session regeneration id errors.


How to check if a plugin has been loaded in jQuery?

Posted: February 9th, 2010 | Author: admin | Filed under: Javascript | Tags: | No Comments »

This tutorial illustrates how to check if a plugin exists or if plugin has been already loaded usingĀ  jQuery. This is particularly useful if you are writing your jQuery code that depends on that plugin.

if(jQuery().plugin_name) {
// plugin exists
} else {
// plugin not loaded
}

A New Beginning

Posted: August 24th, 2009 | Author: admin | Filed under: Personal | 4 Comments »

I just started on my new job at a startup company here in Cebu City. I’m excited on this new opportunity to work with a new team and deal with new projects.


Using Zend Framework’s Paginator Library

Posted: June 23rd, 2009 | Author: admin | Filed under: PHP | Tags: , , | No Comments »

Here’s a tutorial on how to use ZF’s paginator library.

Inside your controller:

    public function displayResultsAction() {
        // First condition gets filtered info from a form and passes it to the model
        if($this->_request->getPost('Submit')) {
            $dept_code= $this->_request->getPost('dept_code');

            $results = $this->report_model->getReports($dept_code);
      	} elseif($this->_request->getParam('dept_code')) {
        // Get the filtered info from the url params being passed by zend paginator
       	    $dept_code= $this->_request->getParam('dept_code');

       	    $results = $this->report_model->getReports($dept_code);
       	} else {
            // do anything here...
            // I just display the default report results
            $dept_code = '';

       	    $results = $this->report_model->getDefaultReports();
        }

        $page = $this->_request->getParam('page', 1);

        $paginator = Zend_Paginator::factory($results);
        //Set item count per page
        $paginator->setItemCountPerPage(20);

        $paginator->setCurrentPageNumber($page);

        $this->view->results = $paginator;
        $this->view->dept_code = $dept_code;
    }

Inside your results view page:

<!-- html code here -->

<table class="view" cellpadding="3" cellspacing="0">
    <thead>
        <tr>
            <th width="100">Id #</th>
            <th width="150">Dept Code</th>
            <th width="200">Department</th>
            <th width="200">Project Name</th>
        </tr>
    </thead>
    <tbody>
    <?php   foreach($this->results as $row) { ?>
        <tr class="view-details">
            <td><?=$row->Id?></td>
            <td><?=$row->DeptCode?></td>
            <td><?=$row->DeptName?></td>
            <td><?=$row->ProjName?></td>
        </tr>
    <?php   }    ?>
    </tbody>
</table>
<br>
<!-- specify path of pagination control under your views in the 3rd param -->
<!-- Adding extra params in the url is specified on the 4th function param here -->
<?=$this->paginationControl($this->results, 'Sliding', 'reports/results-pagination.phtml', array('dept_code' => $this->dept_code))?>

<!-- html code here -->

Inside your pagination file view:

<?php if ($this->pageCount): ?>
<div id="paginationControl">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<?php   if($this->dept_code == '') { ?>
    <a href="<?= $this->url(array('page' => $this->previous)); ?>">&lt; Previous</a> |
<?php   } else { ?>
   <a href="<?= $this->url(array('page' => $this->previous, 'dept_code' => $this->dept_code)); ?>">&lt; Previous</a> |
<?php   } ?>
<?php else: ?>
  <span class="disabled">&lt; Previous</span> |
<?php endif; ?> 

<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
    <?php if ($page != $this->current): ?>
    <a href="<?=$this->baseUrl()?>/reports/display-results?page=<?=$page?><?=($this->dept_code!= '') ? '&dept_code=' . $this->dept_code: ''?>"><?= $page; ?></a> |
    <?php else: ?>
    <?= $page; ?> |
   <?php endif; ?>
<?php endforeach; ?>

<!-- Next page link -->
<?php if (isset($this->next)): ?>
  <a href="<?=$this->baseUrl()?>/reports/display-results?page=<?=$this->next?><?=($this->dept_code != '') ? '&dept_code=' . $this->dept_code: ''?>">Next &gt;</a>
<?php else: ?>
    <span class="disabled">Next &gt;</span>
<?php endif; ?>
</div>
<?php endif; ?>