June 7, 2008

CakePHP - CustomQuery / Pagination

Filed under: cakephp — admin @ 3:49 pm

I’ve been looking for a pagination solution that I could use when I needed to write a custom query using CakePhp 1.2.x.x.
Looking at the cakeapps in the wild page and noticed phtagr. Checked out the demo and noticed that it wasn’t using the native cakephp pagination.

I started reading and hacking and ended up with a solution that I just had to share.
Thanks to Sebastian Felis !!

INSTALL
download: custom_query-0.1.tar.gz
copy custom_query.php to controllers/components/
copy cqpagination.php to views/helpers/

Controller
create a skel controller and copy this content to it.

var $helpers = array('html', 'cqpagination');
var $components = array('CustomQuery');

function beforeFilter()
{
parent::beforeFilter();
$this->CustomQuery->controller =& $this;
$this->CustomQuery->parseArgs();
}

function beforeRender()
{
$this->params[’search’] = $this->CustomQuery->getParams();
}

function index()
{
$sql = “SELECT * FROM {$this->CustomQuery->_tp}members as Member “;
$this->CustomQuery->setSqlQuery($sql);
$data = $this->CustomQuery->paginate();
$this->set(’data’, $data);
}

$this->set(’_action’, $this->action);

View
add this to the view.

$cqpagination->initialize();
?>

echo $cqpagination->prev().’ ‘.$cqpagination->numbers().’ ‘.$cqpagination->next();
?>

NOTE:
I needed pagination for a search via $this->data as a result I have to save the sql query to a session to ensure the pagination
maintain the original sql.

if($this->data) {
$this->Session->delete('current.member.sql.query');
}

$_currentSql = $this->Session->read(’current.member.sql.query’);
if(isset($_currentSql)) {
$sql = $_currentSql;
}
else {

$sql = “SELECT members.id, members.username, members.online_status, members.main_image, members.city, members.state,
profiles.page_views, profiles.personal_quote, profiles.here_for “;
$sql .=”FROM members
JOIN profiles ON members.id = profiles.member_id
WHERE active_member = ‘1′
{$age}
{$gender}
{$city}
{$state}
{$picture}
{$orderBy}
“;
//writing the query to a session to prevent from losing it during pagination.

$this->Session->write(’current.member.sql.query’, $sql);
}

May 17, 2008

CakePHP or Zend Framework..

Filed under: Mashup::keyword, cakephp — admin @ 3:56 am

I’m developing mashupkeyword.com using the Zend Framework and developing a social networking site using CakePHP. It has been GREAT fun using both.

I can use the Zend Framework to develop new and within any application, but really like to “bake” my CRUD and have my MVC without having to think about it. The simple fact that I don’t have to write the initial CRUD helps!!

So I use them both..

MASHUP::Keyword can increase organic traffic

Filed under: Mashup::keyword — admin @ 3:24 am

Since I launched the BETA of MASHUP::Keyword, search has sent 15,149 total visits via 14,109 keywords via 8 sources

when I check google site search

site:mashupkeyword.com
Results 1 - 10 of about 19,300 from mashupkeyword.com.

site:mashupkeyword.com
Results 1 - 10 of about 16,400 from www.mashupkeyword.com.

91.69% of mashupkeyword.com’s traffic is search engine.

Programmableweb post results

Filed under: Mashup::keyword — admin @ 3:00 am

In a previous post I made reference to posting mashupkeyword.com to programmableweb.com since that time I’ve gotten 174 visits from the that domain , avg of 4 page views per visit and avg time on site at over 3 mins.

Bounce rate 27.59%

Not bad at all…

Traffic pattern since Jan 2008 launch

Filed under: Mashup::keyword — admin @ 2:53 am

Reviewing my google analytics. The site has done pretty good when it comes to organic traffic.

  • Jan - 85 Visits 1,471 PV 17.31 P/V (me testing alot)
  • Fed - 68 Visits 808 PV 11.88 P/V (me having people test)
  • Mar - 193 Visits 701 PV 3.63 P/V
  • Apr - 7,224 Visits 14,318 PV 1.98 P/V
  • May - 8,872 Visits 17,527 PV 1.98 P/V

Up until this post I’ve gotten 16,442 visits 34,825 PV 2.12 P/V

92.08% search engine, 4.11% referring and 3.81 direct traffic

As you can see we’re not getting a lot of page views per visit. We’re current working on a design that may encourage additional page views when connecting to the site.

Our current Bounce rate is 73% with an avg time on site at 1.12 sec.

Our goal is to get 5 - 6 PV per visit. Need a redesign HELP!!! lol

March 26, 2008

LyricWiki integration

Filed under: API, Mashup::keyword — admin @ 12:53 am

Initial integration of LyricWiki is done. It was fairly simple.

Enjoy…

March 20, 2008

what’s going on…

Filed under: Mashup::keyword — admin @ 4:29 am

I posted MASHUP::Keyword to programmableweb.com today. Can’t wait to see what type of traffic the site gets as a result.

I also resolved a tricky issue today. I’m integrating a CakePHP application into a CMS theme/layout. My Applications navigation is secondary and the site’s navigation is the primary. The developer on their side asked …

What if we add/remove navigational elements? Will the CakePHP app primary nav update also? I thought for a moment and said yeah…

I made a change to the app/views/layout/default.ctp adding

$url = ‘http://www.domain.com/’;
$response = file_get_contents($url);
preg_match(’/<div id=”menu_horiz”>(.+?)<\/div>/is’,$response, $matches);
echo ‘<div id=”menu_horiz”>’;
echo $matches[1];
echo ‘</div>’;

Not a great solution, but it works… I should move this to the controller so it can be cached. Since, I don’t foresee the navigation changing that often.

later…

March 18, 2008

CakePHP Development

Filed under: cakephp — admin @ 11:54 pm

I’ve spent a lot of my free time this week and last week working on 2 different CakePHP applications One has a signup form and the desire to use of Cake’s $validate() but use custom function to validate the incoming data…

class Member extends AppModel {

var $validate = array(

‘password’ => array(’rule’ => array(’custom’, ‘/^.{6,}$/’), ‘message’ =>’Passwords must be at least 6 characters in length’),
‘password_confirm’ => array(’validatePasswd2′ => array(’rule’ => array(’validatePasswd2′, ‘password_confirm’), ‘message’ => ‘Passwords do not match’)),

);

This link helped a lot….

Zend Framework 1.5 release

Filed under: zf — admin @ 11:54 pm

The Zend Framework is now at version 1.5. I’ve been waiting until it went stable. Need the Zend_Layout component. They also gave the site itself a new feel. Like it…

LyricWiki API

Filed under: API, Mashup::keyword — admin @ 11:34 pm

A co-worker sent me an e-mail today with this link http://www.programmableweb.com/api/lyricwiki
Cool - going to have to allocate some time to integrate this web services..

Coming soon …

Newer Posts »