CakePHP Fulltext Search with Pagination

Posted October 28th, 2010 in CakePHP, Database, MySQL, PHP, Programming by Louie Miranda

This is a working code that I was able to implement for my e-commerce application that uses cakephp full text search with pagination.

<?php
$this->paginate['Publication']['conditions'] = "MATCH(Publication.Code, Publication.Name, Publication.Language) AGAINST ('".$input."' IN BOOLEAN MODE)";
$this->paginate['Publication']['fields'] = "*, MATCH(Publication.Code, Publication.Name, Publication.Language) AGAINST ('".$input."' IN BOOLEAN MODE) AS score";
$this->paginate['Publication']['order'] = "score DESC";
$results = $this->paginate('Publication');
?>

Please make sure that you are using MyISAM on MySQL to fully implement this and you where able to set the full-text capability of the table.

I tried CakePHP Search Plugin

Posted October 28th, 2010 in CakePHP, Database, MySQL, PHP, Programming, Projects by Louie Miranda

So, I tried CakePHP Search Plugin on my current project that I am creating for an e-commerce website.

The search plugin is an easy way to include search into your application. Using this plugin you will able to have paginable search in any controller. Plugin support simple methods to search inside models using strict and non-strict comparing, but also allows you to implement any complex type of searching.

I’ve search my products table and id use the following types parameter.

  • like, This type of search used when you need to search using ‘LIKE’ sql keyword.
  • value, This type of search very usefull when you need exact compare. So if you have select box in your view as a filter than you definetely should use value type.

Overall, it is a great plugin. Although, it did not fit my current requirements for now. :( .  But, I will definitely use it in my future projects.

Have a look here: http://cakedc.com/downloads/view/cakephp_search_plugin

CakePHP Self Adjusting Credit Card Year

Posted October 18th, 2010 in CakePHP, PHP, Programming by Louie Miranda

When I used to program on PEAR, I’ve used the following code to auto-generate succeeding years.

$form->addElement('date', 'CCexpiry', 'Credit Card Expiration',
			  array('format' => 'F-Y',
					'minYear' => date('Y'),
					'maxYear' => date('Y') + 10));

Now, when I used CakePHP (1.2/1.3). They have a similar approach that we can all use.

<?php echo $this->Form->input('cc_expy',
              array('div' => false, 'label' => false, 'type' => 'date',
              'maxYear' => date('Y', strtotime('+ 7 years')),
              'minYear' => date('Y'),
              'dateFormat' => 'Y',
              'default' => date('Y'),
              'orderYear' => 'asc'
              )); ?>

CakePHP: Validate dependent field (select dropdown + input field)

Posted July 15th, 2010 in CakePHP, PHP, Programming, Projects by Louie Miranda

Earlier this week, I was working on a project where I needed to validate two dependent fields.

< ?php echo input('office', array('type' => 'select', 'options' => $nd[0])); ?>
< ?php echo input('office_other', array('maxlength' => '255', 'size' => '35', 'label' => 'Other Office')); ?>

The “office” field is a select (drop down box) from my data array(). What I needed is to be able to add another data from a field and name it as “office_other” where it would initially capture and re-list again new offices if it does not exist.

Continue Reading »

Fatal error: Call to a member function findByFromApplication() on a non-object

Posted January 8th, 2009 in PHP, Programming by Louie Miranda

Geez! I posted this on cakephp mailing list, hoping to find a solution to my problem. Basically, I do wanted to display a small category of applications using an ID. But, weird error keeps popping out of my result.

http://groups.google.com/group/cake-php/browse_thread/thread/f0cc9ab09241f2a4

Attaching a file on CakePHP!

Posted December 5th, 2008 in PHP, Programming by Louie Miranda

This is how I attached a file on CakePHP!

$this->Email->filePaths = array(‘/www/axishift/app/webroot/files/’);
$this->Email->attachments = array(‘attachment.txt’);

Limit feeds on simplepie using cakephp 1.2.x

Posted November 12th, 2008 in PHP, Programming, Projects by Louie Miranda

I am currently working on Simplepie and CakePHP 1.2.x. I have a working code that successfully display xml feeds from different remote sources, a sample can be viewed on my homepage. And, I can’t find how to limit it.

Continue Reading »