Archive

Archive for the ‘PHP’ Category

CakePHP: remove tmp folder from svn control

March 1st, 2010

We’d have to use propset command from SVN.

$#: cd /path/to/repository/cake_project
$#: svn delete app/tmp/*
$#: svn propset svn:ignore '*' tmp/

Now, after you commit the changes your tmp/files won’t be commited to the SVN repo.

Linux, PHP , ,

Cakephp 1.2.x: Distinct Select

September 24th, 2009

Just a reminder for myself:

$foo = $this->$model->find('all', array('fields'=>array("DISTINCT {$model}.dnid")));

CakePHP 1.1.x style used to be:

$this->$model->findAll(null, "DISTINCT {$model}.city");

PHP , ,

Javascript: change img url and anchors title onclick

August 21st, 2009

Recently, was playing around basic javascript Dom functionality elements. The main task was to trigger some functionality via onclick event of JS, and change the view of anchor and img tags inside the DOM component.

For instance we have HTML looking like this:

<a href="javascript:void(0)" onclick="enable_foo()" id="dist_link" title='Enable'><img src="ruler.png" id="ruler_img"/></a>

For this case a basic JS script would look like:

  function enable_foo(){
            var link_text =  document.getElementById('dist_link');
            var my_title = link_text.getAttribute('title');
 
            if(my_title == 'Enable'){
                link_text.firstChild.data = 'Disable';
                link_text.setAttribute('title','Disable');
                document.getElementById('ruler_img').src = "ruller_enabled.png";
            } else if(my_title == 'Disable'){
                link_text.firstChild.data = 'Enable';
                link_text.setAttribute('title','Enable');
                document.getElementById('ruler_img').src = "ruller.png";
            }

For avoiding the changes of the image, you can always fire up the title of anchor tag by removing the call for ‘ruler_img’ (with img tag inside anchor in HTML as well) tag and using:

       link_text.firstChild.data = 'Enable';
       //or
       link_text.firstChild.data = 'Disable';

PHP , ,

CakePHP: jQuery styling of flash messages

January 30th, 2009

CakePHP session flash messages is one of the most useful things for usability, and user notification. Trying to make it more fancy, I came to jQuery framework with its HighlightFade plugin.

Adding just a couple of lines, we can get nice effects, looking the same as Wordpress messages in Posting/Editing:

var $j = jQuery.noConflict(); //I'm using Prototype as well, so we don't need conflicts
$j(document).ready(function() {
if( $j("#flashMessage") ){
$j("#flashMessage").highlightFade({color:'#24F273',speed:2000, iterator:'exponential'});
}
});

Thus, next time you will pass $this->Session->setFlash('Foo');, your flash message with default

flash();?>


will be used with above HighLight effect.

Heap, PHP , , ,

CakePHP: named over url parameters passing

January 5th, 2009

Playing around with CakePHP parameters passing through URL, I’ve noticed that using Paginator helper for listing entities mixes up named and url params in the URL.

For instance, classical paginator URL is:

http://domain.com/controller/action/page:number


which looks like:

Array(
[named] =>Array(
[page] => number
)
)

Any parameter used in the Paginator goes inside of the URL and doesn’t affect the behaviour (in my case, URL param is used for language switching), i.e. http://domain.com/controller/action/?param=foo/page:number
No matter what your $this->params['url']['param'] contains – it won’t reflect on the logic.
Thus, if we use another variable $this->params['named']['foo'], we can always access it in our viewers and utilize it in the $paginator variable, so our URL will look like:
http://domain.com/controller/action/page:number/foo:bar
Useful links:
Additional parameters in $paginator

PHP , ,