czwartek, 9 grudnia 2010

sphinx behaviour

2.0 migration


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

Ajax request in IE7

środa, 10 listopada 2010

rereading book part 2

Use of Model::set
$this->Post->read(null, 1);
 'title' => 'New title',
 'published' => false
 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'
 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.
        "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 
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

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

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
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+'/', { 'data[<?php echo Inflector::singularize($this->name); ?>][weight]': newOrder });
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
All root level categories needs to have parent_id set to NULL

    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
    /*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 (
    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

    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


    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'));

needed Files:

niedziela, 12 września 2010

content sort

I'm going to check how plugin presented on works. As i saw the working example it's pretty much what i was looking for.

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');