Re: Cakephp Ajax helper or Jquery?

2013-05-25 Thread Leigh Mackay
Hi Sam,

Progressive enhancement is a very elegant solution for Ajax and UI. 

Build your app without any Ajax/JavaScript. Use the app controllers before 
filter to change the layout on ajax requests.

public function beforeFilter() {

if ($this->request->is('ajax')) {
  $this->disableCache(); 
  $this->layout = 'ajax'; 
}

}

Ajax requests end up looking something like this.

$.ajax({
  data: $form.serialize(),
  method: 'POST',
  dataType: 'html',
  url: $form.attr('action'),
  success: function (html) {
 var $html = $('').html(html);
  // do whatever you want with the returned chunk of html
  // example: grab the flash message and fade it in
 // make a chicken titty dance
 }
  }); 


Used to-do ajax similar to the Rails convention by sending JavaScript to 
the browser from a separate view template. Most people find progressive 
enhancement so much easier to maintain and it makes front end people happy.

Another tip is to attach your JavaScript handlers to html5 data attributes 
instead of css selectors. It's another separation and makes things even 
easier to maintain.

Leigh


On Friday, May 24, 2013 7:21:45 PM UTC+10, Sam wrote:
>
> Hi Cakephp experts,
>
> I would like to try out Ajax. May I know what are the pros and cons of 
> Cakephp Ajax helper and Jquery? I have never touched ajax and would like to 
> know which is a better choice as a start. Thank you very much.
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to do recursion more than 2 levels deep using the one table?

2013-05-25 Thread DJ
Thanks Andre

Unfortunately tree behaviour doesn't really work for my situation as I need 
the ability for a node/resource/object to have multiple parents.

I believe the problem is related to using the one model. For eample if I 
set up a data model like Country->State->City->Suburb->Street with join 
tables the recursion works fine.

On Saturday, May 25, 2013 5:52:30 AM UTC+10, André Luis wrote:
>
> I didnt really understand what you really want, but it seems that it´s a 
> work for TreeBehavior
>
> In TreeBehavior you have id, parent_id, lft and rght fields... lft and 
> rght are automatically filled by the behavior... The parent_id is the ID of 
> the parent object, them you can use $this->Model->find('threaded'); will 
> return the structure with it´s children.
>
> array(
> [0]=>array(
> 'Model'=>array(
> [id]=>5,
> [parent_id]=>1,
> [something]=>'somevalue',
> [children]=>array(
> [0]=>array(
> 'Model'=>array(
> [id]=>6,
> [parent_id]=>5,
> [something]=>'somevalue'
> )
> )
> )
> )
> )
> )
>
> Em quinta-feira, 23 de maio de 2013 02h54min48s UTC-3, DJ escreveu:
>>
>> Hi
>>
>> I am trying to set up a generic data structure that we can use to map 
>> objects, attributes and relationships. As such I have one table with a id 
>> and name, and a join table with a "parent" id and a "child" id.
>>
>> Data...
>>
>> mysql> select * from resources;
>> ++---+
>> | id | name  |
>> ++---+
>> |  1 | top   |
>> |  2 | 2nd_1 |
>> |  3 | 3rd_1 |
>> |  4 | 2nd_2 |
>> |  5 | 3rd_2 |
>> |  6 | 4th   |
>> |  7 | 5th   |
>> ++---+
>>
>> mysql> select * from resources_resources;
>> ++---+---+
>> | id | a_resource_id | b_resource_id |
>> ++---+---+
>> |  1 | 1 | 2 |
>> |  2 | 2 | 3 |
>> |  3 | 1 | 4 |
>> |  4 | 4 | 5 |
>> |  5 | 3 | 6 |
>> |  6 | 5 | 6 |
>> |  7 | 6 | 7 |
>> ++---+---+
>>
>>
>> Below is my model definition.
>>
>> // Model/Resource.php
>>
>> public $hasAndBelongsToMany = array(
>> 'Children' => array(
>> 'className' => 'Resource',
>> 'joinTable' => 'resources_resources',
>> 'foreignKey' => 'a_resource_id',
>> 'associationForeignKey' => 'b_resource_id',
>> 'unique' => 'keepExisting',
>> 'conditions' => '',
>> 'fields' => '',
>> 'order' => '',
>> 'limit' => '',
>> 'offset' => '',
>> 'finderQuery' => '',
>> 'deleteQuery' => '',
>> 'insertQuery' => ''
>> ),
>> );
>>
>> Controller
>>
>> // Controller/ResourceController.php
>>
>> public function view($id = null) {
>> if (!$this->Resource->exists($id)) {
>> throw new NotFoundException(__('Invalid 
>> resource'));
>> }
>> $options = array('conditions' => array('Resource.' . 
>> $this->Resource->primaryKey => $id),'recursive' => 5);
>> $data = $this->Resource->find('first', $options);
>> debug($data);
>>
>> This outputs as below...
>>
>> array(
>>  'Resource' => array(
>>  'id' => '1',
>>  'name' => 'top'
>>  ),
>>  'Children' => array(
>>  (int) 0 => array(
>>  'id' => '2',
>>  'name' => '2nd_1',
>>  (int) 0 => array(
>>  'id' => '3',
>>  'name' => '3rd_1',
>>  'ResourcesResource' => array(
>>  'id' => '2',
>>  'a_resource_id' => '2',
>>  'b_resource_id' => '3'
>>  )
>>  ),
>>  'ResourcesResource' => array(
>>  'id' => '1',
>>  'a_resource_id' => '1',
>>  'b_resource_id' => '2'
>>  )
>>  ),
>>  (int) 1 => array(
>>  'id' => '4',
>>  'name' => '2nd_2',
>>  (int) 0 => array(
>>  'id' => '5',
>>  'name' => '3rd_2',
>>  'ResourcesResource' => array(
>>

localhost:8080/ does not direct to expected page

2013-05-25 Thread Chandan Pratihast
Dear All
 
I started using the CakePHP (2.3.5) with Apachec 2.2 as the WebServer.
I am observing one problem, that http://localhost:8080/ does not direct to 
the specific page I have routed in route.php.
 
(A) In route.php, I have added this as my first route:
 Router::connect('/', array('controller' => 'welcomes', 'action' => 
'index'));
 
(B) What I observe that if I change the same route as below:
 Router::connect('/welcome', array('controller' => 'welcomes', 'action' => 
'index'));
then with the url: *http://localhost:8080/* welcome it 
renders the specific page as is intended.
 
Not able to figure out why the root url (as in (A)) does not route to 
correct page, instead it routes to the default CakePHP index page.
 
To disable the default routing, I have commented following line in 
route.php:
 /**require CAKE . 'Config' . DS . 'routes.php'; **/
 
Does anyone of you have faced similar problem and how did you solve it?
 
Best regards
Chandan

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.