home | contact us
» » January


If you need to do a bulk find and replace operation on a load of files within a particular folder structure, for example when refactoring some of your code, then instead of trying to use your IDE you could give this little app a try.

It’s called Regexxer:

http://regexxer.sourceforge.net/

And is in the Ubuntu repositories (Software Centre) so is only a couple of clicks away from being installed.

(Note previously I have recommended Search Monkey and I still think that’s a great tool, but it doesn’t seem to do replace, only find).


 

If you use Git for version control and you would like to also keep a track of your database schema (and possibly content though I’m not doing that due to potential file sizes / speed issues) then all you need to do is this simple step:

1. Go to your project folder and into the hidden .git folder, then a sub folder in there called hooks

 cd .git/hooks 

2. Create a file called pre-commit and open it in vim (or whatever text editor you like)

 vim pre-commit 

3. Add a mysql dump command to that file and save it

#!/bin/sh
mysqldump -u DBUSER -pDBPASSWORD  DATABASE --no-data=true > SQLVersionControl/vc.sql
git add SQLVersionControl/vc.sql
exit 0

(note this assumes you have a folder called SQLVersionControl in the root of your project. If you don’t just create it.)

No without any further effort, you will update the schema file on every commit.

eg

git commit -am 'this commit will include a mysql schema dump that has been run just before the commit - sweet :) '

 

With some trepidation I decided that I really had to implement pagination into a Zend Framework project I am working on. Zend Framework is great, but some of the sections can be a little tricky to get your head around at first attempt.

However, less than an hour after first looking at it, I have now got my system spitting out results in a nicely paginated ten at a time. The documentation on the Zend Framework reference is a little sparse but suffice to say that if you are using Zend_Db then actually its pretty easy.

The only bit that is a little tricky is getting the actual page controls to display, as you are left to code your own (though they do supply some code).

One major irritation with the Zend Framework reference guide is that I seem to be unable to copy and paste the code examples, it ends up looking like this:

      <!--
   2.
      See http://developer.yahoo.com/ypatterns/pattern.php?pattern=searchpagination
   3.
      -->
   4.
       
   5.
      <?php if ($this->pageCount): ?>
   6.
      <div class="paginationControl">
   7.
      <!-- Previous page link -->
   8.
      <?php if (isset($this->previous)): ?>
   9.
        <a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
  10.
          &lt; Previous
  11.
        </a> |
  12.

note the line numbers, great.

this tutorial was really useful though:

Here is some code snippets:

Controller

    public function viewAction(){        
        $this->view->input = $input = $this->_request->getPost('search');
        $paginator = $this->_model->tableSearchAllPaginator($input);
        $paginator->setCurrentPageNumber($this->_getParam('page'));
        $this->view->paginator = $paginator;
    }

Model


    public function tableSearchAllPaginator($input, $fields_to_select=null){
        $table = $this->getTable();
        $select = $table->select();
        $fields = $table->info(Zend_Db_Table_Abstract::COLS);
        if(!empty($input)) {
            foreach($fields as $field) {
                $select->orWhere("$field like ?", "%$input%");
            }
        }
        if(!empty($fields_to_select)) {
            $select->columns($fields_to_select);
        }
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
        return $paginator;
    }

View Script

echo $this->partial('_viewtable_page.phtml', array('paginator'=>$this->paginator, 'controller'=>'products'));

View Table Page Partial

if (count($this->paginator)) {
    echo '<h4>Found ' . count($this->paginator) . ' Results</h4>';
    echo '<table class="grid">';
    foreach($this->paginator as $k=>$row) {
        //EC_Debug::dump($k);
        $row = $row->toArray();
        //EC_Debug::diedump($row);
        if($k == 0) {
            echo '<tr>';
            foreach($row as $f=>$v) {
                echo "<th>$f</th>";
            }
            echo '</tr>';
        }
        echo '<tr>';
        foreach($row as $f=>$v) {
            $extra = '';
            if($f=='id') {
                $extra = '<a href="' . $this->url(array('controller'=>$this->controller, 'action'=>'edit', 'id'=>$v), null, true) . '"><img src="' . $this->baseUrl() . '/style/icons/application_edit.png" border="0" alt="edit"></a>';
                $extra .= ' <a href="' . $this->url(array('controller'=>$this->controller, 'action'=>'delete', 'id'=>$v), null, true) . '"><img src="' . $this->baseUrl() . '/style/icons/cancel.png" border="0" alt="delete"></a>';
            }
            echo "<td>$extra $v</td>";
        }
        echo '</tr>';
    }
    echo '</table>';
    echo $this->paginationControl($this->paginator, 'Sliding', '_paginator.php');
}else{
    echo 'no results...';
}

Pagination Controls Partial

<?php if ($this->pageCount): ?>
<div class="pagination">

<?php if (isset($this->previous)): ?>
  <a href="<?= $this->url(array('page' => $this->previous)); ?>">&laquo; PREV</a> -
<?php endif; ?>

<?php
    /* Page links */

    foreach ($this->pagesInRange as $page): ?>
    <a href="<?= $this->url(array('page' => $page)); ?>" <?php if($page == $this->current): ?>id="selected"><?php endif; ?><?= $page; ?></a>
<?php endforeach; ?>

<?php if (isset($this->next)): ?>
 - <a href="<?= $this->url(array('page' => $this->next)); ?>">Next &gt;</a>
<?php endif; ?>

</div>
<?php endif; ?>

 

If you are browsing around a load of files on your object oriented project using the great features like right click - go to definition, then you like me are probably also hankering after a nice backwards and forwards functionality so you can easily jump between places in your project.

After a bit of looking around, it seems that you can by either using the Navigation menu or the key combinations [alt]+[<-] (left arrow) for back and [alt]+[->] (right arrow) for forwards.

That’s better, however a pair of toolbar buttons would be even better, but I can’t seem to find a way to do that. Seems a shame when the functionality is there not to be able to create those buttons.

If you know of a way to do it please add it to the comments!


 

If like me you miss the duplicate tab extension from Firefox 2, this little tip might cheer you up:

Hold down [ctrl] then drag and drop an open tab onto the green + (or any free tab bar space) and you will clone that tab.

Unfortunately this doesn’t clone the history as well, so its not as good as the old duplicate tab, but at least it’s something and its fast.

Found the tip here


 

Edmonds Commerce have been specialising in Magento for a while now. We have been involved in numerous Magento sites doing things ranging from setting up entire stores (including multi store) through to developing custom Magento modules for specific client requirements.

If you are looking for a Magento Developer based in the UK, particularly the Leeds / Bradford area of West Yorkshire then definitely get in touch with us.

2010 has seen the full launch of our Magento Training Courses which are running in Leeds. The first was in early January and we now have two more dates lined up so if you are looking for Magento training then give us a buzz about that and we can give you all the details.

We think Magento is great and we are really happy to be helping more and more UK ecommerce businesses to migrate or establish themselves on this excellent open source ecommerce platform.


 

If your osCommerce checkout starts behaving badly and bits of info seem to go missing eg billing address then you should definitely try this fix before you tear your hair out completely.

Most osCommerce installs store session information to a MySQL table called (suprisingly) sessions.

Sometimes (I have only seen this twice on umpteen osCommerce sites) the sessions table will become corrupted. The irritating thing is that if this happens it seems that the site will not stop working completely with a useful error message, but instead will continue to work but will behave very strangely.

If your osCommerce site is behaving strangely then try this fix.

Open phpMyAdmin and select your SQL database and then copy and paste the following into the SQL section and hit run:

REPAIR TABLE <code>sessions</code>;

 

If you are having a weird problem with your payment modules not saving the configuration when you edit them via the admin, try this to see if it fixes it:

in admin/modules.php

find:

  while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {

and replace it with

  //while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
foreach ($HTTP_POST_VARS['configuration'] as $key => $value){

 

Jquery, arguably the most popular Javascript library has has a new version released.

The release features some dramatic performance improvements, especially on widely used functions like .html()

It also features a host of new functionality and improvements. For full details check out this page:

http://jquery14.com/day-01/jquery-14


 

My favourite PHP framework of the moment, Symfony, is now moving to my favourite version control system – Git.

read more about it Symfony 2 Migration to Git

Its only for the version 2 release, but its a nice step forwards. Github is a really nice system.

The blog post also mentions this great online Git book:

Pro Git

Not actually come across that before, will be handy.


 
rss icon