czwartek, 9 grudnia 2010

sphinx behaviour

http://bakery.cakephp.org/articles/xumix/2009/07/11/sphinx-behavior

2.0 migration

http://cakephp.lighthouseapp.com/projects/42648/2-0-migration-guide

CacheHelper

CacheHelper has been fully decoupled from View, and uses helper callbacks to generate caches. You should remember to place CacheHelper after other helpers that modify content in their afterRender and afterLayout callbacks. If you don't some changes will not be part of the cached content.
CacheHelper also no longer uses <cake:nocache> to indicate un-cached regions. Instead it uses special HTML/XML comments. <!--nocache--> and <!--/nocache-->. This helps CacheHelper generate valid markup and still perform the same functions as before. You can read more CacheHelper and View changes

extandable "details" tables

http://nuts-and-bolts-of-cakephp.com/2010/07/27/keyvalue-tables-and-how-to-use-them-in-cakephp-1-3/

Ajax request in IE7

http://nuts-and-bolts-of-cakephp.com/2010/10/28/fu-ie7/

środa, 10 listopada 2010

rereading book part 2

Use of Model::set
$this->Post->read(null, 1);
$this->Post->set(array(
 'title' => 'New title',
 'published' => false
));
$this->Post->save();
 Model::save - alternative

save(array $data = null, array $params = array())
$params = array(
 'validate' => true,
 'fieldList' => array(),
 'callbacks' => true //other possible values are false, 'before', 'after'
)
http://book.cakephp.org/view/1031/Saving-Your-Data#counterCache-Cache-your-count-1033
 deleteAll(mixed $conditions, $cascade = true, $callbacks = false)
 
unbindModel only affects the very next find function. An additional find call will use the configured association information.
 $this->element('helpbox',
    array(
        "cache" => array('time'=> "+7 days",'key'=>'unique value')
    )
);
 
$this->cakeError(string $errorType [, array $parameters]);
 
debug($var, $showHTML = false, $showFrom = true):
Output from this function is only shown if the core debug variable has been set to a value greater than 0.
 
Session component 
cache
Use the caching engine configured by Cache::config(). Very useful in conjunction with Memcache (in setups with multiple application servers) to store both cached data and sessions.
 
 

wtorek, 9 listopada 2010

rereading book

Some methods i found reading cake book. just to take closer look in the future.

constructClasses, referer

http://book.cakephp.org/view/1017/Retrieving-Your-Data#Complex-Find-Conditions-1030

to be continued.

poniedziałek, 1 listopada 2010

Request action!

Copied from the book:
This allows the requestAction call to bypass the usage of Router::url which can increase performance. The url based arrays are the same as the ones that HtmlHelper::link uses with one difference - if you are using named or passed parameters, you must put them in a second array and wrap them with the correct key. This is because requestAction only merges the named args array into the Controller::params member array and does not place the named args in the key 'named'.

echo $this->requestAction('/articles/view/5');
echo $this->requestAction(array('controller' => 'articles', 'action' => 'view'), array('pass' => array(5)));

wtorek, 19 października 2010

to check

http://bakery.cakephp.org/articles/ronnyvv/2009/02/17/dummy-data-plugin-fill-your-app-with-random-data-that-makes-sense

wtorek, 5 października 2010

czwartek, 16 września 2010

Sequence Plugin

Very nice plugin for keeping table elements in order has been presented here
http://www.neilcrookes.com/2009/02/09/cakephp-sequence-behavior/
To fix the problem with 0-position element movement i slightly changed jquery script provided by Neil

<script type="text/javascript">
$(document).ready(function() {
  $("div.index table ").tableDnD({
    url: "<?php echo Router::url(array('action' => 'save_order')); ?>",
    originalOrder: null,
    onDragClass: "myDragClass",
    onDragStart: function(table, row) {
//        alert(originalOrder);
      originalOrder = jQuery.inArray(row, $(".dragMe", table));
    },
    onDrop: function(table, row) {
      var newOrder = jQuery.inArray(row, $(".dragMe", table));
      if (newOrder != originalOrder) {
        $.post(this.url+'/'+row.id, { 'data[<?php echo Inflector::singularize($this->name); ?>][weight]': newOrder });
      }
    },
  });
});
</script>
and little change in baked index function (just after foreach):
        $class = ' class="dragMe"';
        if ($i++ % 2 == 0) {
            $class = ' class="altrow dragMe"';
        }

saveAll -> saving deep associations

Currently cake doesn't allow saving deep models associations. For example you wan't be able to save in one form (let's assume user/add) User->Article->Tag.

środa, 15 września 2010

Plugin model associations

when defining models relation in plugin, remember to set className as 'pluginName'.'className'

ExtJS + tree behaviour = categories sorting

http://blogs.bigfish.tv/adam/2008/02/12/drag-and-drop-using-ext-js-with-the-cakephp-tree-behavior/
Note:
All root level categories needs to have parent_id set to NULL


Code:
    function reorder(){
   
    // retrieve the node instructions from javascript
    // delta is the difference in position (1 = next node, -1 = previous node)
    $node = intval($this->params['form']['node']);
    $delta = intval($this->params['form']['delta']);
    if ($delta > 0) {
        $this->Category->movedown($node, abs($delta));
    } elseif ($delta < 0) {
        $this->Category->moveup($node, abs($delta));
    }
    // send success response
    exit('1');
   
}
    /*do sortowania*/
    function reparent(){
   
    $node = intval($this->params['form']['node']);
    $parent = intval($this->params['form']['parent']);
    $position = intval($this->params['form']['position']);
   
    // save the employee node with the new parent id
    // this will move the employee node to the bottom of the parent list
   
    $this->Category->id = $node;
    $this->Category->saveField('parent_id', $parent);
   
    // If position == 0, then we move it straight to the top
    // otherwise we calculate the distance to move ($delta).
    // We have to check if $delta > 0 before moving due to a bug
    // in the tree behavior (https://trac.cakephp.org/ticket/4037)
   
    if ($position == 0){
        $this->Category->moveup($node, true);
    } else {
        $count = $this->Category->childcount($parent, true);
        $delta = $count-$position-1;
        if ($delta > 0){
            $this->Category->moveup($node, $delta);
        }
    }
   
    // send success response
    exit('1');
    }

    function sort(){
        $this->layout = 'extjs';
        $this->set('categories', $this->paginate());
        $stuff = $this->Category->find('all',
        array('fields' => array('id','name', 'lft', 'rght', 'parent_id'), 'order' => 'lft ASC'));
        $this->set('stuff', $stuff);
//        debug($stuff);
    }
    /*do sortowania*/
    function getnodes(){
        $this->layout = 'ajax';
        // retrieve the node id that Ext JS posts via ajax
        $parent = intval($this->params['form']['node']);
        $this->log('getNodes: '.$parent, LOG_DEBUG);

        // find all the nodes underneath the parent node defined above
        // the second parameter (true) means we only want direct children
        $nodes = $this->Category->children($parent, true);
        $this->log('getNodes: NODES: '.var_export($nodes,true), LOG_DEBUG);
//        debug($nodes);

        // send the nodes to our view
        $this->set(compact('nodes'));

    }

    function reorderCategories($id = null){
        if ($id === null && $this->Category->id) {
            $id = $this->Category->id;
        } elseif (!$id) {
            $id = null;
        }
        $this->Category->id = null;
//        $res = $this->Category->reorder(array('id'=>null,  'field'=> 'lft','order'=>'ASC'));
//        $this->Category->reorder(array('field' => 'Category.lft', 'order' =>'ASC'));
        $this->Category->reorder();
    }

needed Files:
categories/view/getnodes.ctp

niedziela, 12 września 2010

content sort

I'm going to check how plugin presented on http://www.neilcrookes.com/2009/02/09/cakephp-sequence-behavior/ works. As i saw the working example it's pretty much what i was looking for.

CKeditor/CKfinder

http://blog.beamstyle.com.hk/tutorial-on-integrating-ckfinderckeditor-into-cakephp-with-session-authentication/
This solution worked pritty well for me but i had to change setting up CKFinder for editor
to something like below.

CKFinder.setupCKEditor( null, { basePath : '<?echo $this->webroot;?>/js/ckfinder/'}) ;
  var ck_newsContent = CKEDITOR.replace('long');