Re: how to validate form data

2010-08-04 Thread grigri
You are incorrect in your assumption; you can validate a field with
the $validate array, even if it's not in the database.

This is most often used for I agree checkboxes and whatnot, but it
works with anything.

hth
grigri

On Aug 4, 9:13 am, xiaopang yve...@gmail.com wrote:
 Hello,

 If I want to validate the form input, let's see if it is a email and I
 don't need to store this input in to database, which means the
 $validate array can't do the validation.

 In this case, besides writing reg express, does cakephp provide any
 validation mechanism?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: $hasOne - multiple referencing the same model / alias association

2010-08-02 Thread grigri
This is definitely a belongsTo relationship, and should work fine with
the following code:

?php
class Message extends AppModel {
  var $belongsTo = array(
'Sender' = array(
  'className' = 'User'
),
'Receiver' = array(
  'className' = 'User',
  'foreignKey' = 'recipient_id'
)
  )
}
?

hth
grigri

On Aug 1, 9:46 pm, Dunc duncan.we...@gmail.com wrote:
 Hi,

 I've got a helpdesk application that's being converted to CakePHP and
 I'm trying to reference a model more than once from within a parent
 model, in this case the Message model references the User model twice
 - once for sender, once for reciever.

 According to the Cookbook, as I have a one-to-one database
 relationship (one user has one sender and one user has one reciever) I
 need the $hasOne, though I've also tried using the $belongsTo with the
 same amount of 
 success.http://book.cakephp.org/view/78/Associations-Linking-Models-Together

 I've implimented according to the 
 cookbook:http://book.cakephp.org/view/851/Multiple-relations-to-the-same-model

 The error is that the foreignKey is being applied to the aliased
 JOINed 'child' table, not the parent table.  I get the error (note
 I've removed some of the detail):

 Warning (512): SQL Error: 1054: Unknown column 'Sender.sender_id' in
 'on clause' [CORE/cake/libs/model/datasources/dbo_source.php, line
 673]
 Code | Context
             $out = null;
             if ($error) {
                 trigger_error('span style=color:Red;text-
 align:leftb' . __('SQL Error:', true) . /b {$this-error}/
 span, E_USER_WARNING);
 $sql    =       SELECT `Message`.`id`, `Message`.`sender_id`,
 `Message`.`receiver_id`, `Sender`.`id`, `Sender`.`name`,
 `Recipient`.`id`, `Recipient`.`name` FROM `messages` AS `Message` LEFT
 JOIN `users` AS `Sender` ON (`Sender`.`sender_id` = `Message`.`id`)
 LEFT JOIN `users` AS `Recipient` ON (`Recipient`.`recipient_id` =
 `Message`.`id`)  WHERE 1 = 1   ORDER BY `name` ASC  LIMIT 10
 $error  =       1054: Unknown column 'Sender.sender_id' in 'on
 clause'
 $out    =       null

 My d/b structure (abridged):

 Table Message
   id int autonumber,
   sender_id int,
   recipient_id int

 Table User
   id int autonumber,
   name varchar(100)

 My code:
 ?php
 class Message extends AppModel
 {
   var $name = 'Message';
   var $validate = array(
       // Not relevant
     );

   var $hasOne = array(
     'Sender' = array( // Alias name
       'className' = 'User', // Class of model to link to
       'dependent' = false, // No dependancies
       'foreignKey' = 'sender_id' // field name in Message table
     ),
     'Receiver' = array(
       'className' = 'User',
       'dependent' = false,
       'foreignKey' = 'receiver_id'
     )
   );

   var $hasMany = array
   (
     // Not relevant
   );

   var $hasAndBelongsToMany = array(
     // Not relevant
   );}

 ?

 What am I doing wrong, in particular how can I tell CakePHP that the
 foreign key is in the primary table, not the JOINed tables?

 Thanks in advance,

 Duncan

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Trouble on non-standard database tables

2010-07-22 Thread grigri
It only happens automagically if you conform to the standards - which
you're not because of the legacy naming conventions.

Simply change your input like so:

echo $this-Form-input('id_supplier', array('options' =
$suppliers));

And Bob's your uncle!

hth
grigri

On Jul 22, 1:47 am, guvilla guvi...@gmail.com wrote:
  database tables

 CREATE TABLE IF NOT EXISTS `product` (
   `id_product` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `id_supplier` int(10) unsigned DEFAULT NULL,
   `id_manufacturer` int(10) unsigned DEFAULT NULL,
   `id_tax` int(10) unsigned NOT NULL,
   `id_category_default` int(10) unsigned DEFAULT NULL,
   `id_color_default` int(10) unsigned DEFAULT NULL,
   `on_sale` tinyint(1) unsigned NOT NULL DEFAULT '0',
   `ean13` varchar(13) DEFAULT NULL,
   `ecotax` decimal(17,2) NOT NULL DEFAULT '0.00',
   `quantity` int(10) unsigned NOT NULL DEFAULT '0',
   `price` decimal(20,6) NOT NULL DEFAULT '0.00',
   `wholesale_price` decimal(20,6) NOT NULL DEFAULT '0.00',
   `reduction_price` decimal(17,2) DEFAULT NULL,
   `reduction_percent` float DEFAULT NULL,
   `reduction_from` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
   `reduction_to` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
   `reference` varchar(32) DEFAULT NULL,
   `supplier_reference` varchar(32) DEFAULT NULL,
   `location` varchar(64) DEFAULT NULL,
   `weight` float NOT NULL DEFAULT '0',
   `out_of_stock` int(10) unsigned NOT NULL DEFAULT '2',
   `quantity_discount` tinyint(1) DEFAULT '0',
   `customizable` tinyint(2) NOT NULL DEFAULT '0',
   `uploadable_files` tinyint(4) NOT NULL DEFAULT '0',
   `text_fields` tinyint(4) NOT NULL DEFAULT '0',
   `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
   `indexed` tinyint(1) NOT NULL DEFAULT '0',
   `date_add` datetime NOT NULL,
   `date_upd` datetime NOT NULL,
   PRIMARY KEY (`id_product`),
   KEY `product_supplier` (`id_supplier`),
   KEY `product_manufacturer` (`id_manufacturer`),
   KEY `id_tax` (`id_tax`),
   KEY `id_category_default` (`id_category_default`),
   KEY `id_color_default` (`id_color_default`),
   KEY `date_add` (`date_add`)
 ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

 CREATE TABLE IF NOT EXISTS `supplier` (
   `id_supplier` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(64) NOT NULL,
   `date_add` datetime NOT NULL,
   `date_upd` datetime NOT NULL,
   PRIMARY KEY (`id_supplier`)
 ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

  supplier.php

 ?php
 class Supplier extends AppModel {
         var $name       = 'Supplier';
         var $useTable   = 'supplier';
         var $primaryKey = 'id_supplier';

         var $hasMany = array('Product' = array(
                                          'className'  = 'Product',
                                                  'foreignKey' = 
 'id_supplier',
                                                  'dependent'  = true,)
                                         );

 }

 ?

  product.php

 ?php
 class Product extends AppModel {
         var $name       = 'Product';
         var $useTable   = 'product';
         var $primaryKey = 'id_product';

         var $belongsTo = array(
                                         'Supplier' = array(
                                                 'className' = 'Supplier',
                                                 'foreignKey' = 'id_supplier',
                                                 'conditions' = '',
                                                 'fields' = '',
                                                 'order' = ''));

 }

 ?

  products_controller.php (just showing add method)

 (...)
         function add() {
                 if (!empty($this-data)) {
                         $this-Product-create();
                         if ($this-Product-save($this-data)) {
                                 $this-Session-setFlash(__('The product has 
 been saved', true));
                                 $this-redirect(array('action' = 'index'));
                         } else {
                                 $this-Session-setFlash(__('The product 
 could not be saved.
 Please, try again.', true));
                         }
                 }
                 $suppliers = $this-Product-Supplier-find('list');
                 $this-set(compact('suppliers'));
         }
 (...)

  add.ctp

 div class=products form
 ?php echo $this-Form-create('Product');?
         fieldset
                 legend?php __('Add Product'); ?/legend
         ?php
                 echo $this-Form-input('id_product');
                 echo $this-Form-input('id_supplier');
 (...)

 Why it doesn't show Product form with Suppliers as combobox?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email

Re: calling method passing employee_id variable

2010-07-21 Thread grigri
Ok, this setup will give you a post-redirect-get mechanism.

You could also forgo the requirement for the id to be passed as a
parameter, and just use the posted data[] - this would avoid the
redirect.

Some kind of validation would be good to add, too.

View:

?php
echo $form-create('Lead', array('action' = 'filter'));
echo $form-input(...);
echo $form-end('Go');
?

Controller:

function filter($filter_id = null) {
  if (empty($filter_id)  !empty($this-data['Lead']['employee'])) {
$this-redirect(array('action' = 'filter', $this-data['Lead']
['employee']));
  }
  // Rest of code here
}

hth
grigri

On Jul 21, 10:20 am, james jamesliv...@googlemail.com wrote:
 Im having a real noob time with this!

 Im trying to refine the information that is represented in an index
 based on the selection from a combo box which has a list of employees.
 The user selects the employee they want, clicks go and view then gets
 refined to all records associated to that employee_id.

 so in my controller I have

 function filter($filter_id = null){
   $filterQuery = $this-Lead-find('all',
                         array(
                            'conditions'=array(      'Lead.employee_id' = 
 $filter_id)));
 $this-set-('filterQuery', $filterQuery);

 and my index view I have

  ?php echo $form-input('employee', array
                         ('label' = '',
                         'type' = 'select',
                         'options' = array($employee),   ));?
 ?php echo $form-end('Go');?

 Do i need to link that action to a comnpletely different view eg
 filter.ctp? How do i call the method and pass the id?

 Please help!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: calling method passing employee_id variable

2010-07-21 Thread grigri
Pretty much this:

function filter($filter_id = null) {
  if (empty($filter_id)  !empty($this-data['Lead']['employee'])) {
$filter_id = $this-data['Lead']['employee'];
  }
  // Rest of code here
}

hth
grigri

On Jul 21, 11:00 am, james jamesliv...@googlemail.com wrote:
 Thanks grigiri - i'll get on it!

 out of interest, how would that be accomplished by usnig the data[]
 instead of passing the id parameter? It would be useful i guess to
 avoid the redirect every time if possible

 On 21 July, 10:27, grigri j...@hendersonwebdesign.com wrote:

  Ok, this setup will give you a post-redirect-get mechanism.

  You could also forgo the requirement for the id to be passed as a
  parameter, and just use the posted data[] - this would avoid the
  redirect.

  Some kind of validation would be good to add, too.

  View:

  ?php
  echo $form-create('Lead', array('action' = 'filter'));
  echo $form-input(...);
  echo $form-end('Go');
  ?

  Controller:

  function filter($filter_id = null) {
    if (empty($filter_id)  !empty($this-data['Lead']['employee'])) {
      $this-redirect(array('action' = 'filter', $this-data['Lead']
  ['employee']));
    }
    // Rest of code here

  }

  hth
  grigri

  On Jul 21, 10:20 am, james jamesliv...@googlemail.com wrote:

   Im having a real noob time with this!

   Im trying to refine the information that is represented in an index
   based on the selection from a combo box which has a list of employees.
   The user selects the employee they want, clicks go and view then gets
   refined to all records associated to that employee_id.

   so in my controller I have

   function filter($filter_id = null){
     $filterQuery = $this-Lead-find('all',
                           array(
                              'conditions'=array(      'Lead.employee_id' 
   = $filter_id)));
   $this-set-('filterQuery', $filterQuery);

   and my index view I have

    ?php echo $form-input('employee', array
                           ('label' = '',
                           'type' = 'select',
                           'options' = array($employee),   ));?
   ?php echo $form-end('Go');?

   Do i need to link that action to a comnpletely different view eg
   filter.ctp? How do i call the method and pass the id?

   Please help!



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: alt tag for text box

2010-07-20 Thread grigri
Nope, not without using javascript. Tooltips are generated by the
browser and can't be customised.

There are some custom tooltip javascript solutions around, though - do
a search and I'm sure you could find one.

There's a mootools one here: 
http://davidwalsh.name/mootools-12-tooltips-customize

I'm sure there are countless other ones for mootools, jquery,
prototype and any other framework.

hth
grigri

On Jul 19, 8:58 am, Master Ram ramganga...@gmail.com wrote:
 it is possible to change the color  for this displaying name when i am
 using alt attribute
   array('title' = 'Contact Name')

 in my existing system they are used color.

 when i am taking mouse on over the text box.

 the displaying information should be the the blue color.

 it is possible to change. to blue.

 regards:
 Ram

 On Jul 15, 4:46 pm, grigri j...@hendersonwebdesign.com wrote:

  `alt` is not a tag, it's an attribute.

  Also, although some browsers show an `img`'s alt attribute as a
  tooltip, this is nonstandard. The `title` attribute is what should be
  used for a tooltip, and it works on all elements.

  In short,

  ?php e($form-text('contact_name', array('title' = 'Contact Name',
                                          'value' = '',
                                          'style' = 'width: 80%')));
          ?

  This will make Contact Name appear in the tooltip when the text box
  is hovered.

  hth
  grigri

  On Jul 15, 11:50 am, Jeremy Burns | Class Outfit

  jeremybu...@classoutfit.com wrote:
   I'm happy to be corrected, but I think the 'alt' tag only exists for 
   images (that's HTML, not Cake).

   Also interested to see you using inline styles - are you not using CSS?

   Jeremy Burns
   Class Outfit

   jeremybu...@classoutfit.comhttp://www.classoutfit.com

   On 15 Jul 2010, at 11:42, Master Ram wrote:

Hi,

how to set alt tag for text box, in cakePHP.

i used like this.
?php e($form-text('contact_name', array('alt' = 'Contact Name',
                                       'value' = '',
                                       'style' = 'width: 80%')));
       ?

its not working .

where i missed out.

Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers 
with their CakePHP related questions.

You received this message because you are subscribed to the Google 
Groups CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this 
group athttp://groups.google.com/group/cake-php?hl=en



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Problems with AppHelper

2010-07-20 Thread grigri
The problem here is that FormHelper does not load SessionHelper.

Sub-helpers do not merge automatically (unlike controllers), you have
to do it manually... like so

class AppHelper extends Helper {
  var $helpers = array('Session');

  function __construct() {
if (is_subclass_of($this, 'AppHelper')) {
  $parentVars = get_class_vars('AppHelper');
  $this-helpers = array_merge($parenttVars['helpers'], $this-
helpers);
}
parent::__construct();
  }
}

Please note: this is a very simplified example. It won't handle
plugins properly, or helpers with configuration arrays. But I'm sure
you get the gist.

hth
grigri

On Jul 20, 4:05 am, Galymzhan kozha...@gmail.com wrote:
 Hi, group. I did a blog application in tutorial. I've 2 views like in
 tutorial:
 edit.ctp:
 h1Edit Post/h1
 ?php
         echo $form-create('Post', array('action' = 'edit'));
         echo $form-input('title');
         echo $form-input('body', array('rows' = '3'));
         echo $form-input('id', array('type'='hidden'));
         echo $form-end('Save Post');
 ?

 and view.ctp:
 h1?php echo $post['Post']['title']?/h1
 psmallCreated: ?php echo $post['Post']['created']?/small/p
 p?php echo $post['Post']['body']?/p

 Now I want to override default functionality of url(). I've created
 app_helper.php in /app/ folder.

 class AppHelper extends Helper {
   var $helpers = array('Session'); // I want to use Session helper
   function url($url = NULL, $full = FALSE) {
     if ($this-Session-check('lang')) {
       // here is my custom logic
     }
   }

 }

 The problem is that when I'm trying to edit a post (edit.ctp), I get a
 fatal php error saying FormHelper::$session is undefined. I think that
 session helper isn't loaded.
 But when I view a post (view.ctp) everything works OK and my custom
 url() method works as expected. Help, please. I'm using CakePHP 1.3
 and php 5.2

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Cake POPUP new window

2010-07-16 Thread grigri
If it's static, put the `help.htm` file inside `app/webroot/`, then
link like so:

'onclick' = 'newPopup(' . $html-url('/help.htm') . ');',

hth
grigri

On Jul 16, 8:37 am, Master Ram ramganga...@gmail.com wrote:
 there is no. action is to be done in the help file. that help file is
 static. and it contain only information about the related page.

 On Jul 16, 12:31 pm, mike karthauser mi...@brightstorm.co.uk wrote:

  You can't load HTML files out of a views folder. The file extension needs 
  to be .ctp . Also check you have and action defined with the same name as 
  your view

  Mike Karthauser
  Brightstorm limited
  Tel: 07939252144

  On 16 Jul 2010, at 08:23, Master Ram ramganga...@gmail.com wrote:

   hi..

   i want to popup new window in my ctp. file

   i am using the link. and i want to call help.htm file,

   my HTML file contain in the promoters view folder

   the file name is help.htm.

   i use this code

   ?php e($html-link('Add/edit languages',
                                          'javascript:void(0)',
                                           array(
                        'onclick' = newPopup('http://localhost/
   promodiary_mvc/promoters/languages_help' );,
                                          'class' = 'result_text',
                                          'style' = 'text-
   decoration:none;')));
                      ?

   but i am getting file not found in this server .

   Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
   with their CakePHP related questions.

   You received this message because you are subscribed to the Google Groups 
   CakePHP group.
   To post to this group, send email to cake-php@googlegroups.com
   To unsubscribe from this group, send email to
   cake-php+unsubscr...@googlegroups.com For more options, visit this group 
   athttp://groups.google.com/group/cake-php?hl=en



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: alt tag for text box

2010-07-15 Thread grigri
`alt` is not a tag, it's an attribute.

Also, although some browsers show an `img`'s alt attribute as a
tooltip, this is nonstandard. The `title` attribute is what should be
used for a tooltip, and it works on all elements.

In short,

?php e($form-text('contact_name', array('title' = 'Contact Name',
'value' = '',
'style' = 'width: 80%')));
?

This will make Contact Name appear in the tooltip when the text box
is hovered.

hth
grigri

On Jul 15, 11:50 am, Jeremy Burns | Class Outfit
jeremybu...@classoutfit.com wrote:
 I'm happy to be corrected, but I think the 'alt' tag only exists for images 
 (that's HTML, not Cake).

 Also interested to see you using inline styles - are you not using CSS?

 Jeremy Burns
 Class Outfit

 jeremybu...@classoutfit.comhttp://www.classoutfit.com

 On 15 Jul 2010, at 11:42, Master Ram wrote:

  Hi,

  how to set alt tag for text box, in cakePHP.

  i used like this.
  ?php e($form-text('contact_name', array('alt' = 'Contact Name',
                                         'value' = '',
                                         'style' = 'width: 80%')));
         ?

  its not working .

  where i missed out.

  Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
  with their CakePHP related questions.

  You received this message because you are subscribed to the Google Groups 
  CakePHP group.
  To post to this group, send email to cake-php@googlegroups.com
  To unsubscribe from this group, send email to
  cake-php+unsubscr...@googlegroups.com For more options, visit this group 
  athttp://groups.google.com/group/cake-php?hl=en



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: $this-paginate() inside a Model?

2010-07-14 Thread grigri
It makes no sense for paginate to be called as-is in a model.

The `paginate` method is part of the controller, because it relies on
URL settings (which page, sort order, etc) which only the controller
can access. Allowing the model to access these parameters directly
would violate MVC - in a bad way.

What exactly are you trying to achieve in the model that can't be done
with a find('all')?

hth
grigri

On Jul 14, 12:23 pm, Shaz shazam...@gmail.com wrote:
 (Sorry I meant from my Controllers to my Models!)

 On 14 July, 12:12, Shaz shazam...@gmail.com wrote:

  With my current craze of moving all logic from my models to my
  controllers, a slight problem has risen - namely I can't seem to use
  $this-paginate() in a Model function thats called in a controller.

  $this-find() works perfectly find, and I'm trying to replace $this-find( 
  'all', $conditions ); with $this-paginate( 'Article',

  $conditions ).

  Any advice on either how to get $this-paginate working from a model,
  or perhaps an elegant way of using find() to display my results on
  separate pages?



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Validation problem

2010-07-14 Thread grigri
A regexp that only allows letters, numbers and spaces?

'/^[a-z0-9\\x20]*$/i'

A regexp that only allows words of letters and numbers, each
separated by a single space:

'/^(?:[a-z0-9]+\\x20)*[a-z0-9]$/'

hth
grigri

On Jul 14, 2:44 pm, McBuck DGAF mcbuckd...@gmail.com wrote:
 I would defer to Dr. Loboto on this, since he obviously knows more
 about regex than I do.  Maybe he can suggest the correct rule . . . ?

 My only response to your last post, Felix, is that you cannot remove /
 i since the / is required to delimit the regex.  In other words,
 just removei.

 Good luck.

 On Jul 14, 3:32 am, Dr. Loboto drlob...@gmail.com wrote:

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Database associations

2010-07-09 Thread grigri
This should work:

class Contact extends AppModel {
  var $hasMany = array(
'Call' = array(
  'foreignKey' = false,
  'conditions' = array(
'Call.number = Contact.number'
  )
)
  );
}

hth
grigri

On Jul 9, 12:06 am, Justin Beeler jrble...@gmail.com wrote:
 I'm working with two tables:  Contacts and Calls.

 I want to join the calls with the contacts on a field called
 number (the phone number).  Is there not a way in cake to manually
 join tables and not have it join on a field like [model]_id ?

 If you need any further details, let me know.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: validation messages

2010-07-09 Thread grigri
Your should just be able to return the string...

function checkCheese(tilsit, caerphilly, cheddar) {
  if (!tilsit) {
return Never at the end of the week, sir. Always get it fresh
first thing on Monday.;
  }
  if (!caerphilly) {
return Ah well, it's been on order for two weeks, sir. I was
expecting it this morning.;
  }
  if (!cheddar) {
return Well, I'm afraid we don't get much call for it around
these parts;
  }
  return true;
}

hth
grigri

On Jul 9, 12:12 pm, emanuele emanuel...@gmail.com wrote:
 Hello pals, I ve my own validation method. The method checks three fields.
 Is there any possibility  to customize the message of error depending on the
 failure condtions? For istance:

 function myfunc(a, b, c) {
 if(!a)
 set a message for a;
 elseif(!b) set a message for b;
 elseif(!c) set a message for c;

 }

 thanks in advance
 --
 Emanuele Gringeri
 Computer Engineer
 University of Pisa
 Be my mirror, my sword and shield

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Getting duplicate result when using paginate

2010-07-07 Thread grigri
That's very odd... with that query you shouldn't get any duplicates.

Are you absolutely sure they're duplicates, not just identical rows in
the database? Do they have the same ID?

Try unbinding the associations - if you get the correct results then
add-in the associations one by one.

Otherwise, try setting the fields to DISTINCT User.id,
User.whatever,  Or set the 'group' key to User.id - either
should remove the duplicates.

hth
grigri

On Jul 5, 5:51 pm, WhyNotSmile sharongilmor...@gmail.com wrote:
 Thanks grigri, that's a handy tip.

 I get the following now (I left out the list of fieldnames, because
 there are loads of them):

 SELECT {list of fieldnames}
 FROM `users` AS `User`
 LEFT JOIN `groups` AS `Group` ON (`User`.`group_id` = `Group`.`id`)
 LEFT JOIN `user_types` AS `UserType` ON (`User`.`user_type_id` =
 `UserType`.`id`)
 LEFT JOIN `user_statuses` AS `UserStatus` ON (`User`.`user_status_id`
 = `UserStatus`.`id`)
 LEFT JOIN `user_profiles` AS `UserProfile` ON (`UserProfile`.`user_id`
 = `User`.`id`)
 LEFT JOIN `user_prefs` AS `UserPrefs` ON (`UserPrefs`.`user_id` =
 `User`.`id`)
 LEFT JOIN `user_friends` AS `UserFriend` ON (`UserFriend`.`user_id` =
 `User`.`id`)
 LEFT JOIN `access` AS `Access` ON (`Access`.`user_id` = `User`.`id`)
 WHERE `User`.`group_id` = 1 LIMIT 34

 It looks ok (though I'm no expert in mySQL), but when I ran that as
 just a SQL query, i.e. $results = $this-User-query(); I'm still
 getting the duplicated results.

 Very confused now :s

 On 5 July, 16:27, grigri j...@hendersonwebdesign.com wrote:

  I've never tried setting the debug value from the controller; it's
  possible that it needs to be set up beforehand.

  I do this on some sites like this, in app/config/bootstrap.php:

  if (isset($_GET['setthegorramdebugmode'])) {
          Configure::write('debug', $_GET['setthegorramdebugmode']);

  }

  (Obviously, use a different key than 'setthegorramdebugmode' - use
  whatever you like).

  Then just append '?setthegorramdebugmode=2' on to the end of the URL
  in the browser, and it will enable debug mode, just for you.

  I don't recommend keeping this in place on live sites, however. It
  _should_ be safe, but you never know...

  hth
  grigri

  On Jul 5, 4:12 pm, WhyNotSmile sharongilmor...@gmail.com wrote:

   Thanks.  I did that in the controller (I don't want to change it for
   everything, because it's a live site), but I get:

   (default) 0 query took ms Nr    Query   Error   Affected        Num. rows 
         Took (ms)

   at the bottom.  Am I doing something wrong?

   Thanks,
   Sharon

       Configure::write('debug', 2);

   On 5 July, 16:07, grigri j...@hendersonwebdesign.com wrote:

Open app/config/core.php, change the line (near the top) to
`Configure::write('debug', 2);` [from whatever it was].

Now when you access the page, you'll see the SQL log at the bottom.

hth
grigri

On Jul 5, 3:58 pm, WhyNotSmile sharongilmor...@gmail.com wrote:

 I'm not sure how to get that... I don't have access to the SQL log, as
 far as I know.  Can you suggest where I might look?

 Thanks.

 On 5 July, 15:35, grigri j...@hendersonwebdesign.com wrote:

  What is the corresponding query in the SQL log?

  On Jul 5, 3:29 pm, WhyNotSmile sharongilmor...@gmail.com wrote:

   I'm doing a paginate query, and it's returning the same row 4 
   times.
   The other results in the set are all present and each is shown 
   once.

   Has anyone come across this before?

   My Users controller code is as follows:

      $this-paginate = array(
              'limit' = $limit,
              'conditions' = $find
      );

      $userlist = $this-paginate('User');

   and at the point of calling this code, $limit is 34 and debug on 
   $find
   gives:

   Array
   (
       [and] = Array
           (
               [User.synagogue_id] = 1
           )

   )

   Any ideas what I'm doing wrong?  The record is definitely not
   duplicated in the DB.

   Thanks!



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Getting duplicate result when using paginate

2010-07-05 Thread grigri
What is the corresponding query in the SQL log?

On Jul 5, 3:29 pm, WhyNotSmile sharongilmor...@gmail.com wrote:
 I'm doing a paginate query, and it's returning the same row 4 times.
 The other results in the set are all present and each is shown once.

 Has anyone come across this before?

 My Users controller code is as follows:

    $this-paginate = array(
            'limit' = $limit,
            'conditions' = $find
    );

    $userlist = $this-paginate('User');

 and at the point of calling this code, $limit is 34 and debug on $find
 gives:

 Array
 (
     [and] = Array
         (
             [User.synagogue_id] = 1
         )

 )

 Any ideas what I'm doing wrong?  The record is definitely not
 duplicated in the DB.

 Thanks!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Getting duplicate result when using paginate

2010-07-05 Thread grigri
Open app/config/core.php, change the line (near the top) to
`Configure::write('debug', 2);` [from whatever it was].

Now when you access the page, you'll see the SQL log at the bottom.

hth
grigri

On Jul 5, 3:58 pm, WhyNotSmile sharongilmor...@gmail.com wrote:
 I'm not sure how to get that... I don't have access to the SQL log, as
 far as I know.  Can you suggest where I might look?

 Thanks.

 On 5 July, 15:35, grigri j...@hendersonwebdesign.com wrote:

  What is the corresponding query in the SQL log?

  On Jul 5, 3:29 pm, WhyNotSmile sharongilmor...@gmail.com wrote:

   I'm doing a paginate query, and it's returning the same row 4 times.
   The other results in the set are all present and each is shown once.

   Has anyone come across this before?

   My Users controller code is as follows:

      $this-paginate = array(
              'limit' = $limit,
              'conditions' = $find
      );

      $userlist = $this-paginate('User');

   and at the point of calling this code, $limit is 34 and debug on $find
   gives:

   Array
   (
       [and] = Array
           (
               [User.synagogue_id] = 1
           )

   )

   Any ideas what I'm doing wrong?  The record is definitely not
   duplicated in the DB.

   Thanks!



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Getting duplicate result when using paginate

2010-07-05 Thread grigri
I've never tried setting the debug value from the controller; it's
possible that it needs to be set up beforehand.

I do this on some sites like this, in app/config/bootstrap.php:

if (isset($_GET['setthegorramdebugmode'])) {
Configure::write('debug', $_GET['setthegorramdebugmode']);
}

(Obviously, use a different key than 'setthegorramdebugmode' - use
whatever you like).

Then just append '?setthegorramdebugmode=2' on to the end of the URL
in the browser, and it will enable debug mode, just for you.

I don't recommend keeping this in place on live sites, however. It
_should_ be safe, but you never know...

hth
grigri

On Jul 5, 4:12 pm, WhyNotSmile sharongilmor...@gmail.com wrote:
 Thanks.  I did that in the controller (I don't want to change it for
 everything, because it's a live site), but I get:

 (default) 0 query took ms Nr    Query   Error   Affected        Num. rows     
   Took (ms)

 at the bottom.  Am I doing something wrong?

 Thanks,
 Sharon

     Configure::write('debug', 2);

 On 5 July, 16:07, grigri j...@hendersonwebdesign.com wrote:

  Open app/config/core.php, change the line (near the top) to
  `Configure::write('debug', 2);` [from whatever it was].

  Now when you access the page, you'll see the SQL log at the bottom.

  hth
  grigri

  On Jul 5, 3:58 pm, WhyNotSmile sharongilmor...@gmail.com wrote:

   I'm not sure how to get that... I don't have access to the SQL log, as
   far as I know.  Can you suggest where I might look?

   Thanks.

   On 5 July, 15:35, grigri j...@hendersonwebdesign.com wrote:

What is the corresponding query in the SQL log?

On Jul 5, 3:29 pm, WhyNotSmile sharongilmor...@gmail.com wrote:

 I'm doing a paginate query, and it's returning the same row 4 times.
 The other results in the set are all present and each is shown once.

 Has anyone come across this before?

 My Users controller code is as follows:

    $this-paginate = array(
            'limit' = $limit,
            'conditions' = $find
    );

    $userlist = $this-paginate('User');

 and at the point of calling this code, $limit is 34 and debug on $find
 gives:

 Array
 (
     [and] = Array
         (
             [User.synagogue_id] = 1
         )

 )

 Any ideas what I'm doing wrong?  The record is definitely not
 duplicated in the DB.

 Thanks!



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Serious Help Needed

2009-11-24 Thread grigri
Amit's code won't work as-is, because the keys are being duplicated.

For example, try this in an example script:

$test = array(
  'Bacon' = array('Yummy'),
  'Bacon' = array('Delicious')
);

print_r($test);

You'll see that the first declaration has disappeared. You can only
use a key once in an array.

For validation purposes, do it like this:

var $validate = array(
'email' = array(
array(
'rule' = array('email', 'isUnique'),
'required' = true,
'allowEmpty' = false,
'on' = 'create',
'message' = 'Your Error Message'
),
array(
'rule' = array('email', 'isUnique'),
'allowEmpty' = false,
'on' = 'update',
'message' = 'Your Error Message'
)
),
);

This way both rules will be observed as there are no duplicate keys.

hth
grigri

On Nov 23, 4:54 am, Dave make.cake.b...@gmail.com wrote:
 When you put it like that its so easy to understand. I read the
 cookbook but your example is 100 times better and clearly explained
 when you lay it out like that. thank you very much. that looks like
 exactly what I need.

 Good looking out!

 Thanks,

 Dave

 On Nov 23, 1:29 am, Amit a...@amitvaria.com wrote:

  Take a look at the CakeBook 
  -http://book.cakephp.org/view/127/One-Rule-Per-Field

  var $validate = array(
      'email' = array(
          'rule' = array('email', 'isUnique'),
          'required' = true,
          'allowEmpty' = false,
          'on' = 'create',
          'message' = 'Your Error Message'
      ),
      'email' = array(
          'rule' = array('email', 'isUnique'),
          'allowEmpty' = false,
          'on' = 'update',
          'message' = 'Your Error Message'
      ),
      'url' = array(
          'rule' = array('url', 'isUnique'),
          'required' = true,
          'allowEmpty' = false,
          'on' = 'create',
          'message' = 'Your Error Message'
      ),
      'url' = array(
          'rule' = array('url', 'isUnique'),
          'allowEmpty' = false,
          'on' = 'update',
          'message' = 'Your Error Message'
      ),

  );

  On Nov 22, 8:45 pm, Dave make.cake.b...@gmail.com wrote:

   I cant figure out how to do this.
   I have 2  fields, an email and a url, both are required and need to be
   unique when a user wants to update thier info.

   If the user is only updating 1 field the other required will fail
   because its required. If they enter in the email field their current
   email because it says required it will come back invalid because its
   no longer unique. Vice versa for the url.

   They may only want to change one of the 2 fields information but how
   can you get around this? I dont want them entering in anything thats
   not valid for email / url so i need the validation rules. They are
   both required but how can they edit just 1 field?

   Thanks,

   Dave



--

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




Re: Increment value using CakePHP model functions

2009-11-20 Thread grigri
It's possible in two ways.

First, you've got the `updateAll` function which doesn't escape or
mess with your arguments:

$this-Item-updateAll(
  array('Item.flags' = 'Item.flags + 1'),
  array('Item.id' = 666)
);

One possible problem with this is that it will not call `afterSave`,
trigger behaviour methods, etc... because it's not really a save.
If you need this to work with the rest, the solution is a bit more
long-winded:

$db = ConnectionManager::getDataSource($this-Item-useDbConfig);
$this-Item-set('flags', $db-expression('`Item`.`flags`+1'));
$this-Item-save();

In reality, accessing the datasource and whatnot should be hidden in
the model, but this shows a bare-bones way of getting it working.

hth
grigri

On Nov 20, 12:46 pm, Dave davidcr...@gmail.com wrote:
 Hi everybody,

 I have a quick question that bugs me each time I run into it in a project,
 and then I promptly forget about it.  It is an easy fix, but it is such
 common functionality that I feel there must be some way to do it within
 built in functions rather then a custom query.

 The issue is incrementing a table field without grabbing the previous value,
 using MySQL's default function `tablefield` = `tablefield` + 1 .

 example:

 $this-Item-query('UPDATE `items` SET `flags` = `flags`+1 WHERE
 `items`.`id` = ' . $id);

 I have tried pretty much every way I can think of with model-saveField to
 accomplish this through cake, but I can't get it to work.

 First I set the id with $this-Item-id = $id
 After that I have tried

 $this-Item-saveField('flags','+1');
 $this-Item-saveField('flags',' +1');
 $this-Item-saveField('flags', 'flags+1');
 $this-Item-saveField('flags', '`flags`+1');

 So... is there a way to do this with 1 query within cake? I like to have as
 few custom queries as possible within my application.

 Thanks for any tips,

 who knows, if it isn't built in maybe I will be able to make my first
 contribution to the Core!

 Dave

--

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-...@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=.




Re: Parse error inside my component....plz HELP

2009-11-20 Thread grigri
You're missing the closing brace of
`ServiceCompositionEngineComponent.`

Add another } after closing `getRespType`.

hth
grigri

On Nov 20, 11:36 am, paulos nikolo paulitosthe...@gmail.com wrote:
 Line 18 is abstract class ResponseParser{
 My PHP Version checked ans it is 5.2.6Really weird!

 2009/11/20 AD7six andydawso...@gmail.com



  On 20 nov, 11:14, Paulos23 paulitosthe...@gmail.com wrote:
   Morning Guys,
   I have built a Component for my needs and i get an error
   Parse error: syntax error, unexpected T_CLASS, expecting T_VARIABLE in
   C:\Program Files\xampp\htdocs\voyage~voyage-source\app\controllers
   \components\service_composition_engine.php on line 18

  Try reading line 18 - and check what version of php you're using.

  --

  You received this message because you are subscribed to the Google Groups
  CakePHP group.
  To post to this group, send email to cake-...@googlegroups.com.
  To unsubscribe from this group, send email to
  cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/cake-php?hl=.



--

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-...@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=.




Re: How to enable the right click for a single page out of the whole website?

2009-10-26 Thread grigri

Disabling right-click is a really dick move, and won't actually solve
any problems that you may think it will. Page source, images, pretty
much everything is still accessible. On the other hand, the
frustration of not being able to do right click and open link in new
window or anything else will drive away customers.

So please, don't disable right click. Just don't.

hth
grigri

On Oct 25, 6:45 am, TechMan techtal...@gmail.com wrote:
 Hi all...its been few moments I just joined this group and I require a
 small help if possible from my fellow members of this group...

 Here is what I require- I am working for a website which was developed
 previously by somebody else using the Cake and the whole site is right
 click disabled and I've done almost all of the required modifications
 but one task still left and I need to finish this ASAP, all I need to
 enable the right click for a single page only.. Let me explain more,
 suppose once you bought the product, payment and everything is done,
 then the page which is showing your receipt of the purchase and as
 well as your purchased product information.. I need to make this
 particular page right click enabled...

 Please, anyone of you know how to solve this issue, just give me a
 hint how to fix this..

 Regards,
 TechMan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Preserving get variables using paginator

2009-10-19 Thread grigri

Add this to the top of the relevant view:


 $q = $_GET; unset($q['url']);
 if (!empty($q)) {
 $paginator-options(array('url'=array('?' = $q)));
 }

On Oct 19, 12:32 pm, Alex Seim alex.seimani...@gmail.com wrote:
 I would like to know if there is a way to preserve variables passed
 via form type='get' along with using the pagination. Currently, using
 the pagination helper, when sorting/browsing, get variables disappear.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Hi CakePhp fans, paginator with a alias field.

2009-09-10 Thread grigri

Try this:

class YourModel extends AppModel {
  // ...

  function hasField($name) {
if ($name === 'initial_monthly_payment') {
  return true;
}
return parent::hasField($name);
  }

  function beforeFilter($query) {
if (!empty($query['order'])) {
foreach($query['order'] as $i = $a) {
if (!is_array($a)) {
continue;
}
foreach($a as $k = $v) {
$alias = $this-alias;
$field = $k;
if (strpos($field, '.') !== false) {
list($alias, $field) = 
explode('.', $field, 2);
}
if ($alias == $this-alias  $field ==
'initial_monthly_payment') {
$query['order'][$i] = 'RAND()';
}
}
}
return $query;
}
  }
}

hth
grigri

On Sep 10, 2:36 pm, Cosmin Paul cosmin.p...@gmail.com wrote:
 Because I use the query to mysql for some math.
 CakePhp dose't let me use
 $paginator-sort('Initial Monthly repayments','initial_monthly_payment');
 CODE
    php
     $initial_monthly_payment = MATH FORMULAS;
   /php.
  SQL FIELDS QUERY
     .
     .
     $initial_monthly_payment.'` as `initial_monthly_payment'
     .
     .
  /SQL FIELDS QUERY
 /CODE

 I don't have 'initial_monthly_payment' as a field in the table.

 Haw can I fix this ?

 Thanks for the time!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Finding deeply related models

2009-09-09 Thread grigri

Set recursive to 2?

On Sep 9, 3:21 pm, Bryan Paddock bryanpadd...@gmail.com wrote:
 Hey all,
 How can I get cake to retrieve deeply related info?

 *Property *belongsTo *Location *which in turn belongsTo *Country*

 How can I get $this-Property-find(xx) to return the Country as well?

 I'm having the same problem with *Property *belongsTo *Seller *which
 belongsTo *User *(every time I retrieve data for property I have to fetch
 the User row manually)

 Its happening in all of my finds - It only goes one level deep...

 Any ideas? I've tried setting recursive to 1...

 Bryan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Finding deeply related models

2009-09-09 Thread grigri

Where on earth did you get that idea?

See: http://book.cakephp.org/view/439/recursive

Check the model tests in the source, there are many examples of
setting recursive to 2, 3, and even 6 (in the testReadFakeThread
method).

hth
grigri

On Sep 9, 4:01 pm, Bryan Paddock bryanpadd...@gmail.com wrote:
 recursive only accepts 3 values... -1 / 0 / 1
 Tried that :(

 On Wed, Sep 9, 2009 at 4:57 PM, grigri j...@hendersonwebdesign.com wrote:

  Set recursive to 2?

  On Sep 9, 3:21 pm, Bryan Paddock bryanpadd...@gmail.com wrote:
   Hey all,
   How can I get cake to retrieve deeply related info?

   *Property *belongsTo *Location *which in turn belongsTo *Country*

   How can I get $this-Property-find(xx) to return the Country as well?

   I'm having the same problem with *Property *belongsTo *Seller *which
   belongsTo *User *(every time I retrieve data for property I have to fetch
   the User row manually)

   Its happening in all of my finds - It only goes one level deep...

   Any ideas? I've tried setting recursive to 1...

   Bryan


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



Re: Cake looking for css controller?

2009-09-04 Thread grigri

Looks like your css files are not where they should be. Check all
their filenames and paths.

Because missing asset files (img, css, js, ...) can really slow down a
website (in debug mode especially), and make nonsense of your logs and
sometimes trash your sessions, I usually modifiy the .htaccess file to
ignore missing asset files. These lines should do the trick:

# Do not route missing asset requests through cake
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# This is an exception because they are generated through cake
RewriteCond %{REQUEST_FILENAME} !img/pictures/
RewriteRule ^/?((img|js|css|swf)/.*)$ empty [L]

Where empty is a zero-byte file in the webroot. Depending on your
Apache version you might be able to do this:

RewriteRule ^/?((img|js|css|swf)/.*)$ - [R=404]

Which makes more sense, but some versions don't allow it.

This greatly helps in debugging issues like this.

hth
grigri

On Sep 4, 9:20 am, Ernesto e.fanz...@gmail.com wrote:
 Hello.

 i'm having troubles with one of my cake apps

 basically the app won't load any css.
 if i copy/paste css link in browser's address bar cake returns an
 error page like this:

 Missing Controller

 Error: CssController could not be found.

 Error: Create the class CssController below in file:
 pacchi_alluminio_grezzi\controllers\css_controller.php

 ?php
 class CssController extends AppController {

         var $name = 'Css';}

 ?

 Notice: If you want to customize this error message, create
 pacchi_alluminio_grezzi\views\errors\missing_controller.ctp

 other 4 apps, sharing the same core/webserver with the broken one, are
 working flawlessly

 css are linked via htmlHelper.

 what can i do?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HTML helper in function?

2009-08-12 Thread grigri

Hi Josh,

With that sort of code, you'd be better off putting it in your own
helper. That helper can load its own helpers, so doing links wouldn't
be a problem.

This thread: 
http://groups.google.com/group/cake-php/browse_thread/thread/f3a8243e2226c696
deals with this approach, but for radio boxes not links; the principle
is the same though.

Cheers
grigri

On Aug 12, 12:02 am, Josh joshs.silver...@gmail.com wrote:
 Hi,

 I have the contents of a tree menu stored in a multi-dimensional
 array. The number of dimensions is not fixed, so to turn the array
 into a menu in the View file, I have set up a recurring function. This
 works fine except that I can't call the $html-link() from the
 function.

 Fatal error: Call to a member function link() on a non-object in...

 Any ideas? Is there a way to make the link() function global as you do
 a variable? There are some obvious work-arounds such as writing the
 anchor tag without the html helper, or turning the link array into a
 simpler two dimensional array where I can then iterate the link()
 function. However, I am wonder how I might specifically address the
 question of making the html-link() function available to a function
 within a view file.

 I have a feeling this is either going to be a simple declaration or
 not worth the trouble. Thanks in advance.

 Here is my code:

     //array of links
     key: link title
     value: link location or sub-array
     $linkTree = array(
         'User Management' = array(
             'Permissions' = array(
                 'Set Permissions' = '/tools/setPermissions',
                 'Update ACOS' = '/tools/updateacl',
                 'View/Edit Groups' = '/admin/groups'
             ),
             'User Settings' = '/tools/userSettings',
             'Users' = array(
                 'List' = '/admin/users',
                 'Add User' = '/admin/users/add'
             )
         )
     );

     //output menu function
     function outputMenu ($array, $level) {
         global $levelMarker;

         foreach ($array as $key = $value) {
             if (is_array($value)) {
                 echo $level . $key;
                 echo 'br';
                 outputMenu($value, $level . $levelMarker);
             } else {
                 echo $html-link($level$key, $value);
                 echo 'br';
             }
         }
         echo br;
     }

     //output menu settings
     $levelMarker = '-';
     $level = '';
     $linkTreeSimple = array();

     //output menu
     outputMenu($linkTree, $level);
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Custom Validation Messages

2009-07-23 Thread grigri

Sure, just return the error message from the function:

function isValidGreeble($data) {
  if (somethingWentWrong($data)) {
return 'Something went wrong!';
  }
  if (mt_rand(1,3) == 1) {
return 'It\'s not your lucky day';
  }
  // Success
  return true;
}

hth
grigri

On Jul 22, 5:11 pm, Pr0 Lurk3r pr0lur...@gmail.com wrote:
 I have currently have this problem of a validating a field where there
 is an override which will change the validation criteria. I've got a
 working solution so far, but the message remains the same, which sort
 of gives the wrong impression.

 This would be cool:

 function customValidationFunc( $data ) {
     if( [some critera] ) return true;

     // failed criteria, so issue warning
     if( !$this-data['Tbl']['override'] ) {
          $message = Warning: Field failing;
          // [assign message somehow]
          return false;
     }

      // issued override

      // check some other criteria
      if( [some other criteria] ) return true;

      // still failing, this is an error now
      $message = Error: Field still failing;
      // [assign message somehow]
      return false;

 }

 Is this possible?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Access the model name from a view

2009-07-20 Thread grigri

How about

$modelName = key($this-params['paging']);

That should do the trick.

hth
grigri

On Jul 20, 11:47 am, jordicakephp jordicake...@gmail.com wrote:
 Hi again, my dear baker friends.

 Until now, when I've written this in a controller:

 $paginatedQuery = $this-paginate($this-modelClass);

 I've coded this in a view to access the information that it returns
 (inside a foreach loop, of course):

 $row['ModelName']['user_login']

 That is, hard-coding the name of the model in the view. My doubt is:
 How can I access, from a view, the name of its associated model? I
 haven't been able to find this answer!

 Again, thanks a lot in advance for your time (I promise not to write
 more messages today ;-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: nestedList and individual item attributes (like id)

2009-07-10 Thread grigri

Pretty sure you could adapt the code from this thread to your needs:

http://groups.google.com/group/cake-php/browse_thread/thread/f3a8243e2226c696

hth
grigri

On Jul 10, 9:54 am, d_sturm d.c.st...@googlemail.com wrote:
 Hey,

 I am trying to generate an unordered list with list items having their
 specific attributes, i.e. each li has his own id.
 So I thought it would be nice to pass an array of ids in
 $itemAttributes - but that doesn't work.

 Anyone who could tell me a cake way to do this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: slow loading due to cake's query

2009-07-10 Thread grigri

 sorry, what's eon?

a very long time

hth
grigri

On Jul 10, 11:10 am, gin fgleon...@gmail.com wrote:
 sorry, what's eon?

 On Jul 10, 3:41 pm, AD7six andydawso...@gmail.com wrote:

  On Jul 10, 9:34 am, gin fgleon...@gmail.com wrote:

   please correct me if im wrong but the query which im having a problem
   with is a query called by cake once a model is used.

  k, you're wrong ;).

  It's a query that if you're in production mode is run once every eon.
  Don't do any 'performance' checks with debug  0.

  AD
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Disabling default cakephp routes

2009-06-23 Thread grigri

Just add a rule to your .htaccess:

# If you are using naked UUIDs
RewriteCond %{REQUEST_URI} ^(.*/)entities/view
RewriteRule ^entities/view/([a-fA-F0-9]{32})$ %1$1 [R=301,L]

# If you are using dashed UUIDs
RewriteCond %{REQUEST_URI} ^(.*/)entities/view
RewriteRule ^entities/view/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]
{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$ %1$1 [R=301,L]

hth
grigri

On Jun 23, 2:31 am, Novice Programmer novice.prog...@gmail.com
wrote:
 Hello Guys,

 I am having an EntitiesController with an action view which expects the uid
 as a parameter(uid of the entity to be viewed). I have created a route in
 the configuration file for this situation like:

 Router::connect('/:entity_uid', array('controller' = 'entities', 'action'
 = 'view'),
             array('pass'=array('entity_uid')));

 so that urls look likehttp://x.com/entity_uid
 instead ofhttp://x.com/entities/view/entity_uid

 but some how search engine seems to have indexed the second form 
 i.ehttp://x.com/entities/view/entity_uid which is problematics since it can
 see two urls pointing to the same page.

 Now i am thinking that the default route be given a permanent redirect 
 tohttp://x.com/entity_uid but out of ideas on how to accomplish that. Please
 help.

 I am using the cake build 1.2.3.8166.

 --
 Thanks  Regards,
 Novice.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Form vs. Function

2009-05-26 Thread grigri

From a pure HTTP/REST point of view:

Links only support the GET method. Forms support POST and GET.

Retrieving information should be a GET. If the action adds/modifies a
data entry, it should be a POST.

Therefore, use links.

For example: Would it matter if google/some other bot crawled the
links? If it would not make sense (or if it brought your app crashing
down) then you should definitely be using POST; therefore a form.

hth
grigri

On May 25, 11:57 pm, Dave Maharaj :: WidePixels.com
d...@widepixels.com wrote:
 I currently have a function where a user can click a link to bookmark a page
 to their personal favs.

 The link/button just goes to the function in the controller which gets all
 the info needed to save to the bookmark page from the logged in user id and
 the page they are saving. My question is would it be better or make any
 difference to use a form with just submit/save which would call the same
 function?

 Dave
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Detecting if a link is to an image

2009-05-22 Thread grigri

Just cooked this up for y'all, give it a try

http://bin.cakephp.org/view/969827392

Seems to work ok, might be a bug or two though.

hth
grigri

On May 21, 6:55 pm, JamesF usaexportexpe...@gmail.com wrote:
 before you save the data you could run a regex replace function on
 $this-data['Data']['texarea'] to search for urls and add the html
 tags around it.

 On May 21, 12:01 am, Kyle Decot kdec...@gmail.com wrote:

  I might look into those. I quickly ran into a problem because I tried
  to do $text-autoLink($autolink-images($text)); and the autoLink does
  not have a considerHtml option. Any ideas?

  On May 20, 11:53 pm, Andrew McCafferty andrew.mccaffe...@gmail.com
  wrote:

   Glad it works...

   You might be better trying out the Textile or BBCode helpers though if
   you need more flexibility:

  http://cakeforge.org/projects/textilehelper/http://bakery.cakephp.org...

   On 21 May, 04:15, Kyle Decot kdec...@gmail.com wrote:

Awesome! It's definetly a step in the right direction. I've already
added it here:

   http://www.theskateparkdirectory.com/forums/industry-news/clear-odyss...

I'll probably end up modifying it as there are some other things I
would like it to do. Perhaps when it's done, We can post it on the
bakery! Thanks!

On May 20, 11:03 pm, Andrew McCafferty andrew.mccaffe...@gmail.com
wrote:

 Hi Kyle,

 I've hacked together a helper based on the TextHelper methods that
 should do what you're looking for...

http://bin.cakephp.org/view/1261676226

 Save it to app/views/helpers/autolink.php and include it in your
 helpers array:

 var $helpers = array('Html', 'Form', 'Autolink');

 And in your view:

 ?php echo $autolink-images($post['Post']['content']); ?

 Not very well tested I'm afraid but it should give you some ideas...

 On 21 May, 02:00, Kyle Decot kdec...@gmail.com wrote:

  I would prefer not allowing the users to use a WYSIWYG editor. I 
  would
  rather they use a simple textarea, and if they happen to include a 
  URL
  in their post, then change that into a link, somewhat like $text-

  autoLink() but instead of creating links, create img /'s

  On May 20, 8:46 pm, JamesF usaexportexpe...@gmail.com wrote:

   you might want to check out the jquery fck editor plugin. i use 
   this
   in conjunction with jquery to turn my text area inputs into a 
   wysiwyg
   editor and it saves html to the database. (make sure you sanitize
   first).

   so if you were to go this route you first need to get jquery 
   working
   in its most basic form on your site, than get the fck editor 
   plugin
   for jquery, then install fck to your vendors folder.

   explaining in detail would be a bit lengthy but i hope it gives 
   you
   some ideas.

   On May 20, 3:10 am, Kyle Decot kdec...@gmail.com wrote:

I am building a forum and I want to make it so that if someone 
enters
some text w/ a link to an image in it, my script will take out 
the
link and replace it w/ the image. Anyone know how I would do 
this? I
would also like to do the same thing w/ youtube and vimeo links 
in the
future. Thanks for any insight or help you can provide.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: virtual field in related model

2009-05-15 Thread grigri

Hi Ernesto

This (calculated/dynamic fields) has been brought up several times
here; this is a link to the most relevant thread I can find:

http://groups.google.com/group/cake-php/browse_thread/thread/f823cc7f168cd619

Should help you out

hth
grigri

On May 15, 12:47 pm, Ernesto e.fanz...@gmail.com wrote:
 hello.

 i'm having some troubles :(

 i have an Order model hasMany Item model.

 Item should have a calculated field (Item.Cost/Item.Weight)

 - i modified $queryData in beforeFind callback... but this callback
 doesn't seems to work if the model isn't the primary one.

 - i modified $results in afterFind callback... but cake has many ways
 to load data...

 is there any other way?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Constructing my $conditions array

2009-05-14 Thread grigri

Why not do it this way?

$conditions = array(
  'MATCH(Product.title) AGAINST (? IN BOOLEAN MODE)' = array($blah)
);

I find this notation to be very convienient for this sort of thing
(automatic sanitizing works fine)

hth
grigri

On May 14, 4:30 am, Dr. Loboto drlob...@gmail.com wrote:
 You should properly escape value before put it in SQL:

 'MATCH(SearchIndex.data) AGAINST('.
 ConnectionManager::getDataSource($this-ModelName-useDbConfig)-value
 ($this-params['named']['search']).
 ') IN BOOLEAN MODE)'

 On May 14, 6:50 am, Kyle Decot kdec...@gmail.com wrote:

  Awesome! I thought when you used an array, you had to provide a key.
  Thanks Brian!

  On May 13, 7:41 pm, brian bally.z...@gmail.com wrote:

   I meant that you can add it to the array, though as a string (ie. no key).

   $conditions[] = 'MATCH(SearchIndex.data) AGAINST(\''
          . $this-params['named']['search']
          . '\') IN BOOLEAN MODE)';

   On Wed, May 13, 2009 at 7:24 PM, Kyle Decot kdec...@gmail.com wrote:

Oh, my bad. I must have typed it incorrectly. They should all be
$conditions; I'd rather do it in an array because I have a lot of
different conditions/fields  that can go into the array. Is it
possible to do MATCHES in an array?

On May 13, 7:20 pm, brian bally.z...@gmail.com wrote:
You mention both $conditions  $criteria so it's a bit difficult to
say for sure. But that last bit would probably work better as one
complete string.

'MATCH(SearchIndex.data) AGAINST(\''
        . $this-params['named']['search']
        . '\') IN BOOLEAN MODE)';

On Wed, May 13, 2009 at 6:37 PM, Kyle Decot kdec...@gmail.com wrote:

 I am attempting to construct my array but am having some problems w/
 the $conditions array. I am doing something like:

 $conditions = array(Model.approved=1);

 if($something == $something_else)
 $conditions['Model.something'] = 1;

 if(!empty($search)) {

        $criteria[MATCH(SearchIndex.data) ] = AGAINST( . 
 $this-params
 ['named']['search'] . ') IN BOOLEAN MODE);

 }

 This is not making a valid mysql query. It's putting an equals sign
 right before the AGAINST part. How should I do this? Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Set::extract and Set::combine - help needed

2009-04-24 Thread grigri
Some of what you want to do is possible with the set class; other bits
would be more complicated.

With this approach, the best you could achieve would be a nasty mess
of array_combine, array_keys and various set calls, all nested and
difficult to follow.

Although I love the Set class with all my heart, this is one instance
where I believe a simple loop would be easier to code, easier to
maintain, and ultimately more efficient for the server and the coder.

foreach($data as $i = $bacon) {
  $statusHistory = array();
  foreach($bacon['StatusHistory'] as $eggs) {
$statusHistory[$eggs['StatusName']['text']] = array(
  'since' = $eggs['since'],
  'Changer' = $ggs['Changer']['full_name']
);
  }
  $data[$i]['StatusHistory'] = $statusHistory;
}

Job done!

hth
grigri

On Apr 24, 9:16 am, Faza f...@ansi.pl wrote:
 Hello again,

 this is the array I'm working on:

 Array
 (
     [0] = Array
         (
             [Design] = Array
                 (
                     [id] = 39
                     [design_no] = 1
                     [job_title] = gjgfjyjgyjf
                     [expected_date] = 2009-04-14
                     [customer_id] = 5
                     [designer_id] = 15
                     [status_id] = 1
                     [post_date] = 2009-04-23 13:11:23.247263+02
                     [author_id] = 73
                 )

             [Author] = Array
                 (
                     [full_name] = SKP Admin
                     [id] = 73
                 )

             [Designer] = Array
                 (
                     [full_name] = Jan Grzenda
                     [id] = 15
                 )

             [CustomerNr] = Array
                 (
                     [id] = 5
                     [customers_number_name] = Test (2343)
                 )

             [StatusHistory] = Array
                 (
                     [0] = Array
                         (
                             [since] = 2009-04-21 00:00:00+02
                             [status_names_id] = 1
                             [changer_id] = 74
                             [design_id] = 39
                             [StatusName] = Array
                                 (
                                     [text] = Nowe
                                 )

                             [Changer] = Array
                                 (
                                     [full_name] = John Doe
                                 )

                         )

                     [1] = Array
                         (
                             [since] = 2009-04-23 14:17:11.673985+02
                             [status_names_id] = 2
                             [changer_id] = 74
                             [design_id] = 39
                             [StatusName] = Array
                                 (
                                     [text] = Przydzielone grafikowi
                                 )

                             [Changer] = Array
                                 (
                                     [full_name] = Ed Smith
                                 )

                         )

                 )

         )

 I want to modify the [StatusHistory] branch.
 So far, I'm extracting it using:

 $hist = Set::extract($designs, '{n}.StatusHistory');

 This results in:

 Array
 (
     [0] = Array
         (
             [0] = Array
                 (
                     [since] = 2009-04-21 00:00:00+02
                     [status_names_id] = 1
                     [changer_id] = 74
                     [design_id] = 39
                     [StatusName] = Array
                         (
                             [text] = Nowe
                         )

                     [Changer] = Array
                         (
                             [full_name] = John Doe
                         )

                 )

             [1] = Array
                 (
                     [since] = 2009-04-23 14:17:11.673985+02
                     [status_names_id] = 2
                     [changer_id] = 74
                     [design_id] = 39
                     [StatusName] = Array
                         (
                             [text] = Przydzielone grafikowi
                         )

                     [Changer] = Array
                         (
                             [full_name] = Ed Smith
                         )

                 )

         )

 I've tried endless combine params, but without success.
 I want to achieve this:

 Array
 (
     [0] = Array
         (
             [Nowe] = (StatusName.text) = Array
                 (
                     [since] = 2009-04-21 00:00:00+02
                     [Changer] = John Doe = (Changer.full_name)
                 )

             [Przydzielone grafikowi] = Array
                 (
                     [since] = 2009-04-23 14:17:11.673985+02
                     [Changer] = Ed

Re: Model source code not refreshing

2009-04-22 Thread grigri

 Well there's several hours of my life I'll never get back.  It would
 have been nice if CakePHP logged where it tried to look for a model
 and that it was defaulting to an auto-generated MyModel class in its
 absence.

That's easy enough to do:

class AppModel extends Model {
function __construct($id = false, $table = null, $ds = null) {
  parent::__construct($id, $table, $ds);
  if (strtolower(get_class($this)) == 'appmodel') {
$this-log(Auto-creating model. I really wish I had called
debug_backtrace in order to tell which line called this but I didn't.
Haha.);
  }
}
}

hth
grigri

On Apr 22, 4:18 am, Temujin calebjo...@gmail.com wrote:
  If your model named MyModel, its file should be named my_model.php
  Most of such problems with models are in wrong model file name.

 Sweet mother of mercy, that was it. Renaming app/model/MyModel.php to
 app/model/my_model.php worked. This has got to go down as one of the
 most bone-headed mistakes I've done in a long time.  I guess this is
 what I get for going to-from Java/Spring and PHP/Cake on a daily
 basis.

 Well there's several hours of my life I'll never get back.  It would
 have been nice if CakePHP logged where it tried to look for a model
 and that it was defaulting to an auto-generated MyModel class in its
 absence.

 Thanks Dr. Loboto!

 On Apr 21, 7:19 pm, Dr. Loboto drlob...@gmail.com wrote:

  You should restore original folders structure inside app/tmp - cake do
  not create subdirs itself in runtime and heavily depends on own cache.
  To check consistency in all other app parts is also very good idea.

  Check your log message - is model class MyModel? I think it should be
  AppModel that indicates your model was not loaded, but generic one is
  created.

  If your model named MyModel, its file should be named my_model.php
  Most of such problems with models are in wrong model file name.

  On Apr 22, 7:11 am, Temujin calebjo...@gmail.com wrote:

   Any thoughts on this one?  This project is pretty much halted until I
   can figure out what's going on.

   One though I've had is perhaps some CakePHP file is corrupt or
   missing, so I'm going to do a diff between a fresh CakePHP app and
   mine to see if anything seems out of the ordinary.

   On Apr 21, 10:42 am, Temujin calebjo...@gmail.com wrote:

Here's another thought.

I noticed that in my efforts to remedy this, I completely deleted the
contents of the app/tmp directory (should be harmless, no?).

Looking at that delete, i noticed the file app/tmp/cache/persistent/
cake_core_core_paths which has a serialized array in it with what
appears to be paths to all of the folders cake uses to load things
from.  This file no longer exists, and has not been regenerated.  Is
it possible that you need this tmp file in order for cake to load
models?

Of course, the big hole in this theory is that it seems to be able to
load my controllers/helpers/etc. just fine without it.

On Apr 21, 10:21 am, Temujin calebjo...@gmail.com wrote:

  Google won't show you your own posts until someone replies to them.
  It's very irritating.

 Yes, that is annoying.

 I would make sense if CakePHP was generating a model from just the
 database table since
 I've followed naming convensions.  I have validation rules in my PHP
 model class, and when
 I do $this-log(print_r($this-MyModel, true), LOG_DEBUG) in my
 controller I essentially see
 a stubbed model with the columns derived from the table in the DB.

 What would cause CakePHP to ignore my model though?

 Here's my setup (using cake_1.2.2.8120):

 === app/models/MyModel.php ===
 ?php
 class MyModel extends AppModel {
   var $name = 'MyModel';
   var $validate = array(... validation here ...);}

 ?
 =

 === app/controllers/my_controller.php ===
 ?php
 class MyController extends AppController {
   var $uses = array('MyModel');
   var $helpers = array('Html', 'Javascript');
   var $components = array('Session');

   function index() {
         // this is what logs the empty stubbed model CakePHP appears
 to have generated
         $this-log(\$this-MyModel: .print_r($this-MyModel, true),
 LOG_DEBUG);
         $result = $this-MyModel-save($this-data);
         if ($result) {
             $this-log(valid result);

             $this-Session-setFlash(Sucess,
                                          'default',
                                          array('class' = 'success'));
         }
         else {
             $this-log(invalid result);

             $this-Session-setFlash(Error,
                                          'default',
                                          array('class' = 'error'));
        }
     }}

 ?
 ==

 On Apr 21, 9:28 am, brian

Re: Preferred way to delete with conditions?

2009-04-14 Thread grigri

Looking at the signature for `deleteAll` should answer your question:

 function deleteAll($conditions, $cascade = true, $callbacks = false)

In the version of cake I'm using, it does say in the comments that
$callbacks is not being used, but a quick view of the code shows
that it is.

If you enable both $cascade and $callbacks you should get the effect
you're looking for.

hth
grigri


On Apr 14, 12:28 pm, Martin Westin martin.westin...@gmail.com wrote:
 Hi,
 I frequently need to verify that deleting a record is allowed. I was
 wondering how others handle this kind of conditional delete?

 When finding I can very simply add on an extra condition to check that
 some field matches my requirement. Using the common Blog-analogy it
 might be finding only published posts (published = 1) or similar
 static requirement.

 For deletes I have nothing similar to check, say, published = 0 so
 that I don't delete published posts for example. It might be to
 disallow deleting of users with admin privileges and a number of other
 fairly common cases.

 A good example would be a Folder hasMany dependent File (these are
 reserved words but as a meta-example). When deleting a Folder the user
 doing the deleting needs write access to the folder and each file
 needs to beforeDelete each physical file before deleting the
 database record.

 deleteAll will not work here (afaik) since I need the callbacks to
 fire on the dependent model and I need a condition on the primary
 model.

 I first have to find to verify if the delete can take place, which
 is extra queries (and for-loops). Is there an option better than using
 find('list'), foreach and del ?

 /Martin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Set::extract

2009-04-13 Thread grigri

This should do the trick:

Set::combine($data, '{n}.title', '{n}.no_tags');

hth
grigri


On Apr 13, 3:30 pm, ross.hagg...@googlemail.com
ross.hagg...@googlemail.com wrote:
 Hi i have the following array

 array(
 [0] = Array(
         [title] = Centeral Line Bundle
         [no_tags] = 2
         )

 And i want to create the following.  I'm trying to use the Tagcloud
 helper found in the Bakery.  Someone mentioned i could use
 Set::extract, i've given it a try but no joy.  I used pushDiff to
 merge no_tags and title together.  Any help would be appreciated.

 Ross

 array(
 Centeral Line Bundle = 2, ... //Required for Tagcloud helper 
 -http://bakery.cakephp.org/articles/view/tagcloud-helper
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Get last deleted id from afterDelete?

2009-04-09 Thread grigri

In the afterDelete() callback, $this-id (or $model-id) in a behavior
will refer to the just-deleted model. It's cleared after the callbacks
have been called, just before Model::del() returns.

hth
grigri

On Apr 9, 4:09 pm, park park@gmail.com wrote:
 Hi,

 Working on a set of models, in which after one model got its record
 updated, the Log model will be manipulated accordingly.

 $cascade = true of Model:del() doesn't seem to work, 'coz models
 mentioned above are not associated. (Log model has a field 'item_id'
 that is shared by all other models, recording their ids but
 diffrentiated by another field 'model'. )

 Is it possible to get the last deleted record id from whatever
 beforeDelete or afterDelete callbacks?

 If not, I guess I'll have to extend Model::del in order to get this,
 right? Is there a DRY approach of doing this? (Like writing a
 behavior)

 Many thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Paging with aplhabetical search, not only by page number

2009-04-02 Thread grigri

 Member::findByLetter() uses this condition:

 lower(left(Member.last_name, 1)) = '${letter}'

 I avoided using LIKE because I only want to look at the first letter, anyway.

This sounds like a bad idea for large tables. Assuming you have an
index on the `last_name` field, if you use this...

WHERE `Member`.`last_name` LIKE 'r%'

... it will use the index (it's a range query) and result in speedy
lookups

Using this...

WHERE LOWER(LEFT(`Member`.`last_name`, 1)) = 'r'

...will result in a full table scan, which is horribly inefficient.

(You can use EXPLAIN SELECT to see for yourself)

Case-sensitivity isn't really an issue because you can either set the
collation for the whole table as CI, or just that index. I can't
recall a single instance where the case insensitivity of a database
collation caused an issue, in any of my real-world projects. YMMV, of
course.

hth
grigri

On Apr 1, 4:38 pm, brian bally.z...@gmail.com wrote:
 I have something which does that. But it displays all names for a
 given letter, rather than using a paging limit. I can't figure out a
 clean way to do both.

 public function index($letter = null)
 {
         $letter = is_null($letter) ? 'a' : strtolower((string) $letter);

         $this-set('members', $this-Member-findByLetter($letter));
         $this-set('alpha_list', $this-Member-getAlphaList());
         $this-set('letter', $letter);

         /* render the element only so we don't end up with a nested mess
          */
         if ($this-RequestHandler-isAjax())
         {
                 Configure::write('debug', 0);
                 $this-viewPath = 'elements'.DS.'members';
                 $this-render('alpha_list');
         }

 }

 Member::findByLetter() uses this condition:

 lower(left(Member.last_name, 1)) = '${letter}'

 I avoided using LIKE because I only want to look at the first letter, anyway.

 The rest is a bit more complicated, so I've posted it here:

 http://bin.cakephp.org/view/1433101916

 This is all based on some stuff I had with a non-Cake site. That one
 actually had a lot of the heavy lifting done in the DB using pl/python
 (Postgres).

 On Wed, Apr 1, 2009 at 3:52 AM, meximex meixne...@gmail.com wrote:

  hi,
  if i have an application with a list of 1000 items and want to jump to
  the page of the items starting with M. how could y do that?

  do i have to implement that by my self?

  if you would do it by yourself, how would you do it?

  create a loop for every letter and an sql that counts the items before
  that letter?

  isnt there something better in mysql?

  thx for your help!
  meximex
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: What's wrong here?

2009-04-02 Thread grigri

Best guess, your model files are misnamed. Make sure they are in the
correct directory and named `invoice.php` and `invoice_product.php`.

hth
grigri

On Apr 2, 12:53 pm, logout stefano...@gmail.com wrote:
 Sorry, I used the tab on my keyboard and send it twice even before
 discribing the problem to the end.

 So, if I call this:

 $things = $this-Invoice-InvoiceProduct-myFind();

 I get the error.

 But if I call this:

 $things = $this-Invoice-InvoiceProduct-find('all');

 It works perfectly.

 What's wrong here... I can't call a user defined function through the
 model associations. But I have other models with other user defined
 functions and there everything is OK.

 On Apr 2, 2:46 pm, logout stefano...@gmail.com wrote:

  Guys, this is driving me mad...

  I have two models that are connected with the $hasMany and $belongsTo
  variables:

  class Invoice extends AppModel {
          var $name = 'Invoice';
          var $hasMany = array('InvoiceProduct');

  }

  and

  class InvoiceProduct extends AppModel {
          var $name = 'InvoiceProduct';
          var $belongsTo = array('Invoice');

  function myFind() {
     return $this-find('all');

  }
  }

  OK. Now in the InvoicesController I have this call:

  $things = $this-Invoice-InvoiceProduct-myFind();

  Of cource, the myFind() is implemented in the InvoiceProduct model,
  for a simple examle:

  function myFind() {
     return $this-find('all');

  }

  And it doesn't work. I get this message:

  Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
  check the manual that corresponds to your MySQL server version for the
  right syntax to use near 'myFind' at line 1

  When I click on the Warning and then on the context I get this:

  $sql    =       myFind
  $error  =       1064: You have an error in your SQL syntax; check the 
  manual
  that corresponds to your MySQL server version for the right syntax to
  use near 'myFind' at line 1
  $out    =       null
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: An external URL pointing to the application

2009-04-02 Thread grigri

You need to construct the link manually, with the url constructed with
the second parameter (full) set to true:

a href=?php echo $html-url(array('controller' = 'internets',
'action' = 'destroy'), true); ?Click here to destroy the internet/
a

Or like this, if you so prefer:

echo $html-tag('a', 'Click here to destroy the internet', array(
  'rel' = 'dangerous',
  'href' = $html-url(array('controller' = 'internets', 'action' =
'destroy'), true)
));

Of course, if the email is in plain text and you don't need an HTML
link, just use

echo $html-url(array('controller' = 'internets', 'action' =
'destroy'), true);

hth
grigri

On Apr 2, 2:16 pm, Antônio Marco idelfonso.alme...@gmail.com wrote:
 Hi folks, morning (here in Brazil)!

 I'm developing an application wich sends an e-mail to a claimant. This
 e-mail contains a complete URL that points to an action wich validates
 the claimant's e-mail account.

 The problem is I have two development environments: test (my CPU) and
 production (the HTTP server).

 So, how to send the correct ***domain*** in the URL, automaticaly?

 CakePHP controllers has both $base and $here properties relative to
 the webroot of the application, but these properties don't solve my
 problem.

 Thanks for any help.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Filtering by HABTM model count

2009-03-27 Thread grigri

When you use the `bindModel` call, use a different alias.

Example:

$this-bindModel(array('hasOne'=array(
'AlbumsImageBacon'=array(
  'className' = 'AlbumsImage'
),
'ImageBacon'=array(
 'className'='Image',
 'foreignKey'=false,
 'type'='INNER',
 'conditions'=array(
 'ImageBacon.status = 0',
 'ImageBacon.id = 
AlbumsImageBacon.image_id')
 )
)
));

hth
grigri

On Mar 27, 12:31 am, volve bclay...@gmail.com wrote:
 My problem: Show the user 4 Albums where each Album has = 1 Images.

 I started this project in CakePHP 1.1 and realized quickly I couldn't
 create an elegant solution, so I've recently upgraded to 1.2.2 and am
 trying again.

 My code below works correctly and returns a wonderful array with all
 the pieces of data I need. The really odd thing is that after Cake has
 sent the first query, joining all the necessary tables, it then goes
 back to query the Image model 4 times, each time failing because it
 attempts to use the non-joined AlbumsImage HABTM association in the
 where clause.

 Here's the error and offending SQL:

 Warning (512): SQL Error: 1054: Unknown column 'AlbumsImage.image_id'
 in 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php,
 line 525]

 SELECT   `image`.`id`,`image`.`title`,`image`.`host`,`image`.`path`
 FROM     `images` AS `image`
 WHERE    `image`.`status` = 0
          AND `image`.`id` = `albumsimage`.`image_id`
 ORDER BY `image`.`created` ASC

 I don't know why this query is even being issued, but as I say it's
 all the more odd because the main query (below) returns successfully.

 SELECT
 `album`.`id`,`album`.`user_id`,`album`.`title`,USER.id,USER.username,`user`.`id`
 FROM     `albums` AS `album`
          LEFT JOIN `users` AS `user`
            ON (`album`.`user_id` = `user`.`id`)
          LEFT JOIN `albums_images` AS `albumsimage`
            ON (`albumsimage`.`album_id` = `album`.`id`)
          INNER JOIN `images` AS `image`
            ON (`image`.`status` = 0
                AND `image`.`id` = `albumsimage`.`image_id`)
 WHERE    `album`.`status` = 0
 GROUP BY `album`.`id`,`album`.`title`
 HAVING   Count(* ) = 1
 ORDER BY `album`.`created` DESC,`image`.`created` ASC
 LIMIT    4

 Here is the method of the Album model I use to query Albums where
 Image count = 1:

   function gimme($num=6) {
     $contain = array(
       'AlbumsImage',
       'Image'=array('ImageSize',
                      'fields'=array
 ('Image.id','Image.title','Image.host','Image.path'),
                      'order' = 'Image.created ASC'
                      ),
       'User'=array('fields'='User.id,User.username'));

     $this-resetAssociations(); // just in case

     $this-bindModel(array('hasOne'=array('AlbumsImage',
                                            'Image'=array(
                                                  'className'='Image',
                                                  'foreignKey'=false,
                                                  'type'='INNER',
                                                  'conditions'=array(
                                                      'Image.status =
 0',
                                                      'Image.id =
 AlbumsImage.image_id')
                                                  )
                                            )
                            ));

     $albums = $this-find('all', array('contain' = $contain,
                                     'conditions' = array
 ('Album.status'='0'),
                                         'fields' = array
 ('Album.id','Album.user_id','Album.title'),
                                          'order' = 'Album.created
 DESC',
                                          'limit' = $num,
                                          'group' = array
 ('Album.id','Album.title HAVING COUNT(*) = 1'))); // we only want
 Albums with 1 or more images
     return $albums;
   }

 I've been trying to figure this out all day so would /really/
 appreciate any insights into this weird SQL error.

 Thanks everyone!
 -volve
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Pagination with Random Order?

2009-03-25 Thread grigri

Try something like this:


class ProductsController extends AppController {
  var $paginate = array(
'Product' = array(
  'order' = 'RAND()',
  'limit' = 10
)
  );

  function random() {
if ($this-Session-check('Products.randomSeed')) {
  $seed = $this-Session-read('Products.randomSeed');
}
else {
  $seed = mt_rand();
  $this-Session-write('Products.randomSeed', $seed);
}
$this-paginate['Product']['order'] = sprintf('RAND(%d)', $seed);

// ...
$products = $this-paginate();
// ...
  }
}

Should do the trick, might need a bit of tinkering though

On Mar 25, 3:48 pm, Tim t...@gurske.com wrote:
 So I have a list of 50 products. I need to display 5 pages of 10
 products each. They need to be in random order so no product has
 priority.

 I have everything built with sorting. pagination and other options but
 I'm not sure how to handle this... can it be done?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Redirect after an edit operation in a paginated view

2009-03-09 Thread grigri

I did just this a while ago; it worked fine for my purposes:

$this-redirect($this-referer());

However, there was a problem. If, after editing an item, it appears in
a different page, then it just won't work.

Example: your index is listed alphabetically. You're on page 3, and
click edit on the entry Curried Animals: Aardvark to Zebra. You edit
this to Aardvark to Zebra: A guide to wild curries. It returns you
to page #3 but your entry is now on page #1. Is this the expected
result?

It might be in some cases, and not in others. One of my clients
remarked that it _wasn't_ what they wanted, because it made what they
were doing slower.

I have taken to having a dropdown, similar to the one PhpMyAdmin
offers, where the user can select the next action. Back to index,
Find this item, View this item, Edit again, Add new, ... not
all items on each edit, of course, only the relevant ones. The
redirect functionality is in a component (which also generates
appropriate data to set in the select options).

hth
grigri

On Mar 9, 10:26 am, Danny Lieberman onlyj...@gmail.com wrote:
 This would seem to be a trivial task.  I have a list of paginated
 rows.   I want to be able to click on an edit operation on a
 particular page  1 and return to the same page.  I save the referer
 on entry to the function and redirect to the saved referer after the
 database save operation - but the controller always returns to the
 controller index method no matter what the user chooses.

 I'm running in production mode - perhaps this is related to debug=0?

 Here is the code:
         function fu($id = null) {
                 $refer = Controller::referer();    // save the calling
 page
                 if (!$id  empty($this-data)) {
                         $this-Session-setFlash(__('Invalid Contact',
 true));
                         $this-redirect(array('action'='index'));
                 }
                 echo $refer;
                 if (!empty($this-data)) {
                         if ($this-Contact-save($this-data)) {
                                 $this-Session-setFlash(__('The
 Contact has been saved', true));
                 //              $this-redirect(array
 ('action'='index'));
                                 $this-redirect($refer); // redirect
 back to the calling page after save
                         } else {
                                 $this-Session-setFlash(__('The
 Contact could not be saved. Please, try again.', true));
                         }
                 }
                 if (empty($this-data)) {
                         $this-data = $this-Contact-read(null, $id);
                 }
                 $this-set('contact', $this-Contact-read(null,
 $id));

 Looks like something really stupid is breaking this but I cant figure
 out what

 Danny
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Converting SQL query to Cake query

2009-03-06 Thread grigri

Try this:

$this-Page-bindModel(array(
  'hasOne' = array(
'PageViewTotal' = array(
  'className' = 'PageView',
  'type' = 'inner'
)
  )
));
$results = $this-Page-find('all', array(
  'fields' = array('Page.*', 'COUNT(PageViewTotal.id) AS
page_view_count'),
  'group' = 'Page.id',
  'order' = 'page_view_count DESC',
  'limit' = 10
));

hth
grigri

On Mar 6, 3:36 pm, RyOnLife ryan.mckil...@gmail.com wrote:
 This doesn't work because 'view_count' is not a field. All of the view data
 is contained in the 'View' model, keyed to the 'Page' model (Post in your
 example).

 Maybe it would help if I share the full details of my models, tables and the
 SQL query/result I would like to create in Cake:

 Page hasMany PageView:

 CREATE TABLE IF NOT EXISTS `pages` (
   `id` int(11) NOT NULL auto_increment,
   `user_id` int(11) NOT NULL,
   `title` varchar(100) NOT NULL,
   `slug` varchar(100) NOT NULL,
   `created` datetime NOT NULL,
   PRIMARY KEY  (`id`),
   FULLTEXT KEY `title` (`title`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

 PageView belongsTo Page:

 CREATE TABLE IF NOT EXISTS `page_views` (
   `id` int(11) NOT NULL auto_increment,
   `page_id` int(11) NOT NULL,
   `user_id` int(11) default NULL,
   `user_ip` int(10) unsigned default NULL,
   `created` datetime NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED;

 SQL query:

 SELECT Page.*, COUNT(*) AS views FROM
 pages AS Page
 INNER JOIN page_views AS PageView ON Page.id = PageView.page_id
 GROUP BY Page.id
 ORDER BY COUNT(*) DESC  
 LIMIT 10 OFFSET 0;

 Returns these fields:

 id, user_id, title, slug, created, views

 The first five fields are those from the Page model and the sixth field,
 views, is a count of how many times the Page.id primary key is used as a
 PageView.page_id foreign key.

 Thanks for the help. I know Cake is supposed to make SQL easier, but I am
 having trouble making the jump from SQL to Cake queries where the SQL is
 more involved than simple SELECT statements.

 Stu-2 wrote:

  $topTen = $this-Post-find('list',
  array(
  'fields' = array('Post.id', 'Post.view_count'),
  'order' = array('Post.view_count DESC'),
  'limit' = 10
  )
  );

  this worked for me.

 --
 View this message in 
 context:http://n2.nabble.com/Converting-SQL-query-to-Cake-query-tp2434189p243...
 Sent from the CakePHP mailing list archive at Nabble.com.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: What do you develop in (ide, text editor, etc.)?

2009-03-02 Thread grigri

Notepad++ for everything. Every IDE I've tried has been horrendously
slow, and I've got used to not having auto-completion.

On Mar 2, 9:48 am, WyriHaximus webmas...@wyrihaximus.net wrote:
 Using jEdit atm untill I can svn2web working switching to Eclipse PDT
 then.

 On Mar 2, 12:37 am, danfreak freakclimb...@gmail.com wrote:

  I used Zend Studio, then Aptana at work, but I'm now sticking with
  TextMate ;o)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: AJAX rendering text

2009-02-25 Thread grigri

I believe it's the opacity change that makes IE text jaggedy.

There might be a proper workaround but try these:

* Make sure the element you're fading has an opaque background colour
* Try fading an overlay element to mask the text, rather that fading
the text itself

I ran into this a while ago and one of them worked, can't remember
which though

hth
grigri

On Feb 24, 7:17 pm, WidePixels d...@widepixels.com wrote:
 Does anyone know how to get rid of the text rendering in steps in IE?
 When I update a DIV everything works correctly but the text is
 rendered all jagged then after a second it snaps in an looks
 correct. I saw a page on the web about it but now can not find it.

 link code:

 ?php echo $ajax-link('update', '/users/update_profile/' .$user
 ['User']['slug'].'',
                  array('update' = 'user_div',
                                            //'class' = 'edit_btn',
                                            'loading'= 
 'Element.show(\'frame_load\'); new Effect.Opacity
 (\'user_div\' , { from: 1, to: 0 })',
                                            'loaded'= 'new 
 Effect.Opacity(\'user_div\' , { from: 0, to:
 1 })',
                                            'complete' = 
 'Element.hide(\'frame_load\'); Element.show
 (\'user_div\')'
         ,null, FALSE)); ?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problem with forms : some fields are blank in edit mode

2009-02-13 Thread grigri

Hi Ed,

Some browser (eg FF) may override the contents of the form fields on
page load.

Check the generated source code and see if the `value` attribute is
correctly and consitstently filled. It it is, then your cake code is
fine. You can force the browser to use the values you specified by
calling `form.reset()` through javascript when the page is loaded.

If, on the other hand, the html code is not consistent then you'll
have to look more carefully at the cake code. Form field data is not
kept through a redirect, for example, so if you redirect on an error
then you can't expect the data to be transmitted without extra work
(sessions).

hth
grigri

On Feb 13, 12:09 pm, netedo edouardhie...@gmail.com wrote:
 Hello,
 Here my strange problem :
 I have got o simple form with one table.
 The add works well, like the view mode. That means, data is saved
 directly.

 But in the edit mode, sometimes, a field appears blank.
 Other times all fields appear with the right data.

 I can't understand... and I tested in local and in an hosting, the
 same behavior occurs.

 Many thanks.

 Ed
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Link to Image using Helpers

2009-02-12 Thread grigri

Assuming you meant `app/webroot/img`,

// This is a text link to an image:
echo $html-link('This is an image', '/img/some-image.png');

// This is an image link to another image:
echo $html-image('small-image.png', array('url' = '/img/big-
image.png'));

// So is this:
echo $html-link(
  $html-image('small-image.png'),
  '/img/big-image.png',
  array('escape' = false)
);

If you didn't mean `app/webroot/img`, and you're actually storing
images in `app/img`, then let me be the first to say UR DOIN IT RONG!
If you want a file to be directly web-accessible then it belongs in
the webroot folder. Anything not in the webroot folder cannot be
accessed directly through a url.

If you really really want to keep images outside of the webroot then
you'll have to serve them with a MediaView or some other method - not
a great idea for static images since it creates quite a bit of server
overhead. If you're going for dynamic images, on the other hand, then
it makes perfect sense [though I'd invest in some cacheing].

hth
grigri

On Feb 12, 9:08 am, Adrian Marte adrian.ma...@gmail.com wrote:
 Hi,

 How can I create a link to an image (in the app/img directory) using
 the HTML helper? I only find solutions for image links, but not links
 to images.

 Thank,
 Adrian
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Turning $_GET/$_POST into named params

2009-02-12 Thread grigri

RewriteCond %{QUERY_STRING} ^q=(.*)$
RewriteRule ^(products/search(/[^/]+)*)/?$ /$1/q:%1? [R=301,L]

Will rewrite (for example) `/products/search/page:2/?q=bacon` to `/
products/search/page:2/q:bacon`

hth
grigri

On Feb 11, 9:08 pm, Miles J mileswjohn...@gmail.com wrote:
 Anyone have an idea how to do the .htaccess?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM Search Problem

2009-02-12 Thread grigri
If Coupon belongsTo Merchant and Merchant hasMany Address, then you'd
need recursive=2 to get the Address from a find on Coupon.

If you want to handle it all in a single find, I'd strongly suggest
using the Containable behavior; recursive=2 finds tend to be quite
slow and fetch a lot of redundant, unnecessary data without it.

hth
grigri

On Feb 11, 7:37 pm, Jesse jesseainsk...@gmail.com wrote:
 I know that HABTM problems are pretty frequnt. I've been doing lots of
 research and almost got this figured out. A little boost would really
 be appreciated.

 The Downlow...

 Merchants
 Merchants hasMany Addresses
 Merchants hasMany Coupons
 Coupons HABTM tags
 tags HABTM coupons

 I've got a search for the tags area that then returns the Coupon
 information. Everything works fine except I need to pull some more
 information. My problem is I am unbinding/binding information on the
 fly to do the search and I think this is causing my recursion problem.
 Here's the code.

 $cat_count = count($conditions['OnsaleCouponsCategory.id']);

                 $this-OnsaleCoupon-unbindModel(array
 ('hasAndBelongsToMany' = array('OnsaleCouponCategory')));
                 $this-OnsaleCoupon-bindModel(
                     array(
                         'hasOne' = array(
                             'OnsaleCouponsOnsaleCouponsCategory' =
 array(
                                 'foreignKey' = false,
                                 'type' = 'INNER',
                                 'conditions' = array
 ('OnsaleCouponsOnsaleCouponsCategory.onsale_coupon_id =
 OnsaleCoupon.id')
                             ),
                             'OnsaleCouponsCategory' = array(
                                 'foreignKey' = false,
                                 'type' = 'INNER',
                                 'conditions' = array(
                                     'OnsaleCouponsCategory.id =
 OnsaleCouponsOnsaleCouponsCategory.onsale_coupons_category_id',
                                     //'OnsaleCouponsCategory.id' =
 array(14)
                                     'OnsaleCouponsCategory.id' =
 $conditions['OnsaleCouponsCategory.id']
                                 )
                             )
                         )
                     )

                 );

                 $found_coupons = 
 $this-OnsaleMerchant-OnsaleCoupon-find('all', array(

                         'recursive' = 1,
                     'group' = array(
                             'OnsaleCoupon.id',
                             //'OnsaleCoupon.title HAVING COUNT(*) = 1'
                             'OnsaleCoupon.title HAVING COUNT(*) = ' .
 $cat_count
                     )
                 ));

 Here a print_r for $found_coupons:
 Array
 (
     [0] = Array
         (
             [OnsaleCoupon] = Array
                 (
                     [id] = 38
                     [onsale_merchant_id] = 16
                     [title] = Free Soft Drink!
                     [content] = Get a free soft drink with the
 purchase of any meal!
                     [datestart] = 2009-02-05 08:14:00
                     [dateend] = 2009-02-05 08:14:00
                     [retail_price] =
                     [sale_price] =
                 )

             [OnsaleMerchant] = Array
                 (
                     [id] = 16
                     [name] = Happy Joes Pizza
                     [website] =http://www.happyjoes.com
                     [about_us] = About us!
                     [hours] = Hours!
                     [logo] = image/jpeg
                     [onsale_merchants_category_id] = 2
                 )

             [OnsaleCouponsOnsaleCouponsCategory] = Array
                 (
                     [id] = 115
                     [onsale_coupon_id] = 38
                     [onsale_coupons_category_id] = 14
                 )

             [OnsaleCouponsCategory] = Array
                 (
                     [id] = 14
                     [title] = American
                     [onsale_coupons_categories_division_id] = 3
                     [0] = Array
                         (
                             [id] = 3
                             [title] = Golfing
                             [onsale_coupons_categories_division_id] =
 4
                             [OnsaleCouponsOnsaleCouponsCategory] =
 Array
                                 (
                                     [id] = 117
                                     [onsale_coupon_id] = 38
                                     [onsale_coupons_category_id] = 3
                                 )

                         )

                     [1] = Array
                         (
                             [id] = 11
                             [title] = Chinese
                             [onsale_coupons_categories_division_id] =
 3
                             [OnsaleCouponsOnsaleCouponsCategory] =
 Array

Re: Help with calculated field being backticked to death

2009-02-11 Thread grigri

I haven't tried this in a while, but I seem to remember adding extra
parentheses helped.

Try these:

'(Modelname.foreign_id0 AS result)'
'(Modelname.foreign_id0) AS result'
'((Modelname.foreign_id0) AS result)'
'(((Modelname.foreign_id0) AS result))'

One of them _should_ work

hth
grigri

On Feb 11, 11:34 am, Martin Westin martin.westin...@gmail.com wrote:
 Hi,
 I am trying to order by a calculation (in a pagination) but my
 calculation is being backticked to death. I can't find a way to write
 this so that is works.

 I have:

 var $paginate = array(
         'Modelname' = array(
                 'fields'=array(
                         'Modelname.id',
                         'Modelname.fieldname',
                         'Modelname.foreign_id',
                         'Modelname.foreign_id0 AS result' // no matter what 
 I put here I
 get an sql syntax error
                 ),
                 'limit' = 10,
                 'order' = 'result ASC, Modelname.fieldname ASC'
         )
 );

 This results in:
 SELECT `Modelname`.`id`, `Modelname`.`fieldname`,
 `Modelname`.`foreign_id`, `Modelname`.`foreign_id0` AS `result`
 FROM...

 and about 10 other variations I have tried. If I just copy the query
 and remove the badly placed backticks I get a working query. I just
 can't figure out how to trick Cake into not messing with the
 calculation. Doing simple SUM(somefield) AS some_sum has never caused
 any problems but I have not been able to find a function in MySQL
 that would do a simple greater than comparison.

 thanks in advance
 /Martin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Turning $_GET/$_POST into named params

2009-02-11 Thread grigri

I generally do what Martin suggests - with a redirect.

However, you can speed up the process (for the user, not the
developer!) like this:

* Add an .htaccess rewrite rule to rewrite the url before it even hits
cake. This is much faster that redirecting from a cakephp controller
action.

* With unobtrusive javascript, intercept the form submission/link
click and alter the url on-the-fly. For javascript users this means no
server redirect and faster response times.

hth
grigri

On Feb 11, 8:40 am, Miles J mileswjohn...@gmail.com wrote:
 So I have a search/browse system thats plugged into pagination.
 Everything works fine as a $_POST, the data is returned and paginated
 BUT the second I resort the results using the pagination, I lose all
 the search queries/terms.

 How can I turn $_GET or $_POST into named params so that they are
 continually passed to pagination?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Prevent direct action request

2009-02-11 Thread grigri

class ControllerC extends AppController {
  function A1() {
// blablabla
  }

  function A2() {
if (empty($this-params['requested']) || ($this-params
['requested']!=1)) {
  $this-redirect('http://www.milinkito.com/swf/bart.php?texto=I
+will+not+call+this+action+directly');
}
// blablabla
  }
}

hth
grigri

On Feb 11, 12:39 pm, Bogdan Ursu bogdanvu...@gmail.com wrote:
 Hey guys,

 I have this setup: Controller C has two actions A1 and A2. In the view
 of A1, in a loop I am doing requestAction(A2). My problem is that A2
 can also be requested directly, by writing in the address bar of the
 browser: C/A2.
 Is there anyway of preventing the execution of A2 directly?

 PS: Don't argue with the current code structure, because I am not
 willing to change it. I just want to disable direct access to A2, if
 possible; so that it will only be accessible from A1's view via the
 requestAction.

 Thanks a lot
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Credit Card Expiration Date Validation

2009-02-11 Thread grigri

Here's an excerpt from a model I had for validating this sort of
thing:

class Order extends AppModel {
  var $name = Order;

var $validate = array(
// ...
'card_valid_from' = array(
'on' = 'card',
'allowEmpty' = false,
'rule' = array('validateRelativeDate', false),
'message' = 'Time travellers are not allowed to shop 
here'
),
'card_valid_to' = array(
'on' = 'card',
'allowEmpty' = false,
'rule' = array('validateRelativeDate', true),
'message' = 'That card has expired'
),
// ...
);

function deconstruct($field, $data) {
if ($field == 'card_valid_from' || $field == 'card_valid_to') {
$data['day'] = '01';
}
return parent::deconstruct($field, $data);
}

function validateRelativeDate($date, $inFuture) {
$now = date('Y-m') . '-01';

$date = reset($date);

if ($inFuture) {
return $date = $now;
}
else {
return $date = $now;
}
}
}

The view form elements look like this (excerpt):

echo $form-inputs(array(
'legend' = 'Pay by Credit Card',
'card_valid_from' = array('type' = 'date', 'dateFormat' = 'MY'),
'card_valid_to' = array('type' = 'date', 'dateFormat' = 'MY')
));

hth
grigri

On Feb 10, 7:38 pm, JoshSchramm josh.schr...@gmail.com wrote:
 Hey all,

 I cant seem to find anything online to explain this so i'm hoping you
 all can help a bit.

 I am validating credit card information and right now i'm working on
 ensuring the user enters an expiration date.
 For this i have to fields one for month and one for year both using
 $form-input('type'='date')

 When they post the data looks like
 [ExpirationMonth] { [month]=XX }, [ExpirationYear] { [year]=}

 On the back end I'm trying to validate this and it doesnt want to
 work. My validate array looks like this.

 'ExpirationMonth.month'=array(
                         'numeric'=array(
                                 'rule'='numeric',
                                 'allowEmpty'=false,
                                 'required'=true,
                                 'message'='ExpirationMonthInvalid'
                         ),
                         'between'=array(
                                 'rule'=array('between', 1, 12),
                                 'allowEmpty'=false,
                                 'required'=true,
                                 'message'='ExpirationMonthInvalid'
                         ),
                 ),
                 'ExpirationYear.year'=array(
                         'notEmpty'=array(
                                 'rule'='notEmpty',
                                 'allowEmpty'=false,
                                 'required'=true,
                                 'message'='ExpirationYearInvalid'
                         ),
                         'numeric'=array(
                                 'rule'='numeric',
                                 'allowEmpty'=false,
                                 'required'=true,
                                 'message'='ExpirationYearInvalid'
                         )
                 )

 no matter what i do i don't get an error message back.

 To clarify a bit more i have a 'empty'='Choose Month (or year)' in
 the drop downs so I'm just trying to make sure the user selected
 something other than that option.

 Any ideas?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Stop code execution in beforeFilter() and render a view

2009-02-11 Thread grigri

Try this (it's just an idea, not tested)

class SomeController extends AppController {
  var $_cancelAction = false;

  function beforeFilter() {
if (!$answerMeTheseQuestionsThree) {
  // Aaarghh...
  $this-_cancelAction = $this-params['action'];
  return;
}
  }

  function dispatchMethod($method, $params = array()) {
if ($method == $this-_cancelAction) {
  return false;
}
return parent::dispatchMethod($method, $params);
  }
}

hth
grigri

On Feb 11, 2:39 pm, guigouz guig...@gmail.com wrote:
 Returning false keeps the flow running (cake will execute further
 actions).
 Any other workaround ?

 On 20 jan, 16:48, brian bally.z...@gmail.com wrote:

  I think you need to return false.

  On Tue, Jan 20, 2009 at 11:53 AM, Ron ron8...@gmail.com wrote:

   I am creating a check in my app_controller beforeFilter() method and
   if the check fails I want to stop execution of the action and render a
   view.

   I have something like this

   function beforeFilter()
   {
   .

   if (!$check)
   {
     $data = array('msg'='my message');
      $this-set('data', $data);
      $this-layout = 'json';
      $this-viewPath = 'json';
      $this-render('index');
      exit();
   }

   }//end beforeFilter()

   The problem is the code will not render the view, and if i take out
   the ( exit(); ) the action will go on. Any help would be appreciated.

   Thank You,

   Ronald Almeida
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: CAKEPHP variable in querystring

2009-02-10 Thread grigri

Cake isn't doing this, your PHP setup is.

CAKEPHP is the name of the session cookie. In most setups, session
handling is done by an http cookie sent through the headers. When
either the server admin or the intended site visitors wear tinfoil
hats, the 'url rewriting' functionality is used, which adds the
session cookie as a GET parameter to all links and form targets, which
is what you're seeing here.

If you have access to the box's config, you need to edit php.ini and
set `session.use_cookies` to 1. If you don't then ask your hosting
provider to do so. If they can't, get a better host.

hth
grigri

On Feb 10, 8:45 am, cyk0tik michaeldow...@gmail.com wrote:
 Hi,

 Cake seems to be adding on an encrypted string to all my links in my
 app..

 eg. instead ofhttp://www.website.com/index.php, I 
 gethttp://www.website.com/index.php?CAKEPHP=446fd3WEgh543fnz

 Can anyone tell me why it's doing this?

 Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How can I perform normal PHP code within the cake directory ?

2009-02-10 Thread grigri

Just move the file/files into app/webroot. From there you can call
them normally.

hth
grigri

On Feb 10, 1:07 pm, hasentopf mathias.koell...@googlemail.com wrote:
 Dear cake-users.

 I found no answer so far for my question, maybe you know a solution:

 I converted a web project completely to CakePHP.

 I would like to leave only one module (a calendar for a apartment
 rental) in the old state, because the transformation to Cake would be
 too expensive.

 My question: How can I perform normal PHP code within the cake-
 directory without a Missing Controller error message?

 Any ideas?

 Best Regards
 Mathias
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: MooTools Ajax Pagination

2009-02-10 Thread grigri

What more do you want? That looks like a very neat starting point form
ajax pagination with mootools (I use mootools as my js framework of
choice; don't do a huge amount of ajax though).

Why doesn't this seem like the best option? What's wrong with it?

On Feb 10, 3:34 pm, Arak Tai'Roth nielsen.dus...@gmail.com wrote:
 Is there anything else out there? This is definitely an option, but it
 doesn't seem like the best option to me.

 On Feb 9, 6:59 pm, Websta* subscripti...@webprogression.co.nz
 wrote:

  Here is the code of a really basic mootools JS object that can pretty
  much be dropped in for paging a standard cake index view

 http://pastebin.com/d43137c

  All you have to do is wrap your view code in a div and specify that id
  as your pagingDivId

  This is extremely basic and doesnt make allowance for request failure
  events etc - just the basics.

  HTH,

  Paul.

  On Feb 10, 11:45 am, Arak Tai'Roth nielsen.dus...@gmail.com wrote:

   The project that I am currently working on is constrained by the fact
   that I have to use MooTools for a few things we are using. I also
   don't really want to use Prototype as the load times in certain cases
   aren't exactly friendly.

   So I was wondering if there is anywhere I can learn how to implement
   AJAX Pagination with MooTools, I know there is a tutorial in the
   bakery for JQuery, I was hoping for something similar using MooTools.
   Or if someone can give me some examples here.

   Any help is appreciated, thank you.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Doing a NOW() in save().

2009-02-05 Thread grigri

You can also use DataSource::expression() to handle functions; if you
need something other than NOW().

More details in this thread: 
http://groups.google.com/group/cake-php/browse_thread/thread/cb5542bf68211624

hth
grigri

On Feb 5, 7:17 am, Miles J mileswjohn...@gmail.com wrote:
 Oh derr, that totally didn't cross my mind. Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Calling select queries within find()

2009-02-05 Thread grigri

Sure thing.

This is a copy of my overridden datasource for a project I did last
month: http://bin.cakephp.org/view/1781729779

It: handles the above thingy, performs a backtrace on queries so you
can tell which file/function generated which query (neat for
debugging) and syntax-highlights it. Each of these functions is in a
separate... function. So if you only want one of them then delete the
other functions.

Has anyone else overridden the datasource for other useful purposes?

hth
grigri

On Feb 4, 9:56 pm, Miles J mileswjohn...@gmail.com wrote:
 Awesome, can you give an example/snippet of overriding the datasource
 to do just that?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamically remove a helper in a controller

2009-02-04 Thread grigri

Remove it from the $helpers member variable in the controller's
`beforeFilter` method:

class WhateverController extends AppController {
  function beforeFilter() {
foreach($this-helpers as $k = $v) {
  $helper = is_int($k) ? $v : $k;
  if ($helper == 'Unwanted') {
unset($this-helpers[$k]);
break;
  }
}
return parent::beforeFilter();
  }
}

hth
grigri

On Feb 4, 11:26 am, maxmil max...@gmail.com wrote:
 I have a situation where i want a certain helper included in all of my
 controllers except one.

 I would like to be able to put the helper in my app_controller and
 explicitly remove it from the one controller that doesn't use it
 rather than having to manually add it to all but one of my
 controllers.

 The $helper property of each controller is an array of strings not
 objects removing the helper from there does not work.

 Does anyone know the right way to do it?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Calling select queries within find()

2009-02-04 Thread grigri

 I posted a similar query here last week. I was hoping to use Set class
 to do the same. I guess grigri wasn't around ;-)

Sorry mate, must have missed that one. I haven't been checking this
group as often as I used to.

afaik, there's no way to do this with the Set class alone :( There are
some things it just can't do. Although I suppose I could write up a
diff patch for adding functionality for a Set::replace(),
Set::multiInsert() or some such method.

My preferred method of dealing with this situation is to modify the
datasource. I always override the datasource anyway, so it's no biggie
to override resultSet() it I need to. The advantage here is that there
isn't an extra loop over the resultset; hence a performance increase
over using an afterFind() method for larger result sets.

Specifically, I override it so that a field specified as Bacon__eggs
(that's a double-underscore) will slot into the 'Bacon' entry.

With this, the above query becomes:

'fields' = array('TeamsUser.*', (SELECT COUNT(id) FROM teams_users
AS TeamsUser WHERE TeamsUser.team_id = Team.id AND TeamsUser.status =
'approved') AS TeamsUser__totalMembers)

And the resultset is as expected.

hth
grigri


On Feb 4, 2:39 am, brian bally.z...@gmail.com wrote:
 I posted a similar query here last week. I was hoping to use Set class
 to do the same. I guess grigri wasn't around ;-)

 Teknoid suggested this method:

 http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-field...

 On Tue, Feb 3, 2009 at 8:41 PM, Miles J mileswjohn...@gmail.com wrote:

  Ok I got it working, but its outside of the array I want. Anyway to
  get it in there?

  [TeamsUser] = Array
                                 (
                                     [id] = 1
                                     [team_id] = 1
                                     [user_id] = 2
                                     [role] = leader
                                     [status] = approved
                                     [joinDate] = 1231636154
                                 )

                             [0] = Array
                                 (
                                     [totalMembers] = 6
                                 )

  Heres my query:

  'fields' = array('TeamsUser.*', (SELECT COUNT(id) FROM teams_users
  AS TeamsUser WHERE TeamsUser.team_id = Team.id AND TeamsUser.status =
  'approved') AS totalMembers)

  I tried doing AS TeamsUser.totalMembers and it didnt work.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validate belongsTo model in select element - inList does not seem to work?

2009-02-04 Thread grigri

Something like this should work:

(code not tested, but theory sound)

class Customer extends AppModel {
  var $validate = array(
'country_id' = array(
  array(
'rule' = array('custom', '/^[a-z]{2}$/'),
'required' = true,
'message' = 'Please select the country that you reside in.'
  ),
  array(
'rule' = array('checkCountry'),
'message' = Please stop playing with firebug.'
  ),
)
  );

  function checkCountry($data) {
$countryCode = reset($data);
return $this-Country-hasAny(array('Country.code' =
$countryCode));
  }
}

hth
grigri

On Feb 4, 7:01 am, Braindead markus.he...@gmail.com wrote:
 Brian, your solution seems to be ok, but there is one problem:

 Let's assume the selectbox contains the 3 items de, nl and dk.
 Selecting one of the items would pass the validation.
 But aa, ab, ac, ad, ae and so on would also pass the validation
 without being valid.

 So what is the way to go? I guess you have to write a custom
 validation rule, that checks if the selected item is part of the
 association.

 Hope that helps.
 Markus
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Set::extract() with threaded and associated data

2009-01-23 Thread grigri

If you paste the exact format of the data array you're trying to
process, I'm sure I can write the params for you to extrat it.

Do a debug() or print_r() on the data [or a subset... enough to get
the structure] and paste it here.

hth
grigri

On Jan 23, 12:42 pm, Jon Bennett jmbenn...@gmail.com wrote:
 hi,

 I'm sure this is possible, it's just alluding me at present!

 I have 2 models:

 MixtureCategory
 Mixture

 MixtureCategory is a parent/child self association, so I'm getting the
 data like so:

 $this-data = $this-MixtureCategory-find('threaded');

 I'm looping over $this-data in my view, but only need to display info
 about the top level category, and would like to output list of links
 to all mixtures that belong to a second level category.

 foreach($this-data as $category):

         // name
         echo $category['MixtureCategory']['name'];

         // mixtures
         $mixtures = array_combine(
                 Set::extract($category, 
 'children.{n}.MixtureCategory.{s}.Mixture.name'),
                 Set::extract($category, 
 'children.{n}.MixtureCategory.{s}.Mixture.slug')
         );

         // test
         debug($mixtures);

 endforeach;

 this gives me total garbage though.

 any ideas?

 cheers,

 Jon

 --

 jon bennett
 w:http://www.jben.net/
 iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Label information for Multiple Checkboxes

2009-01-20 Thread grigri

// controller
$aliquots = $this-Aliquot-find('all', array(
  'conditions' = whatever,
  'fields' = array(
'Aliquot.id',
'Aliquot.additive',
'Specimen.type',
'Specimen.draw_date'
  ),
  'recursive' = 0
));
$this-set('aliquots', Set::combine($aliquots,
  '{n}.Aliquot.id',
  array(
'{0} [{1} / {2}]', // Format
'{n}.Aliquot.additive', // Field #0
'{n}.Specimen.type', // Field #1
'{n}.Specimen.draw_date' // Field #2
  )
));
// view
echo $form-input('Aliquot', array('options' = 'aliquots', 'multiple'
= 'checkbox'));

Alternatively, if you want the checkboxes grouped - say by specimen
type, then use this:

$this-set('aliquots', Set::combine($aliquots,
  '{n}.Aliquot.id',
  array(
'{0} [{1} / {2}]', // Format
'{n}.Aliquot.additive', // Field #0
'{n}.Specimen.type', // Field #1
'{n}.Specimen.draw_date' // Field #2
  ),
  '{n}.Specimen.type'
));
// view
echo $form-input('Aliquot', array('options' = 'aliquots', 'multiple'
= 'checkbox'));

hth
grigri

On Jan 20, 2:32 pm, Tony Thomas truet...@gmail.com wrote:
 On Jan 16, 12:22 am, brian bally.z...@gmail.com wrote:

  I think you could probably easily build the structure you want using
  Set in afterFind() (if not in the find itself). Can you post an
  example  of the sort of array you would need if you were, say,
  displaying each option in an html table? Like if you did a straight
  find('all', $your_conditions).

 Just to keep it simple, I've only got two fields in my 'find' until I
 work out the logic. Once I have that worked out, I should be able to
 open it up to however many fields I want.

 $aliquots = $this-Aliquot-find(
                                                 'all',
                                                 array('fields' = array(
                                                         'Aliquot.id',
                                                         'Specimen.type'),
                                                         'conditions' = 
 'Aliquot.box_id IS NULL', 'limit' = '0, 100',
 'recursive' = 2
                                                         )
                                                 );
 $this-set('aliquots', $aliquots);

 Then in the view:

 echo $form-input('Aliquot', array( 'label' = false,
                                                                         
 'type' = 'select',
                                                                         
 'multiple' = 'checkbox',
                                                                         
 'options' = $aliquots));

 The problem is that 'options' above doesn't seem to display a nested
 array correctly. It's fine if I only define a single field in my find,
 but since it uses the array for the labels as well as the value for
 each checkbox, I can't define more information there to be displayed
 only in the label. At least I haven't figured out how.

 I could loop through and define each checkbox separately, but making a
 multiple selection is difficult in that scenario unless I abandon the
 form helpers altogether and just hand code the form.

  On Thu, Jan 15, 2009 at 5:02 PM, Tony Thomas truet...@gmail.com wrote:

   I follow you up to this bit:

   ?php

   echo $form-input(
         'Category',
         array(
               'type'='select',
               'multiple'='checkbox',
               'options'=$ids,
               'label'=false
               )
         );
   ?

   This doesn't seem to solve the problem of getting the other
   information into my label. In fact, it's the exact method I'm using
   now. I understand using $this-find('all', $options) and extract() to
   separate the ids from the rest of the information, but how do I get
   the other information displayed in my form? This method still leaves
   me with checkboxes and ids, but no other info.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Issues with conditions in view

2009-01-20 Thread grigri

I'm guessing that you're putting the findbyoffice function in the
wrong file - either in the controller, or a misnamed model file.

In any case, you don't need it. Completely remove that function, and
have this as your index() function:

function index() {
  $this-Rapportini-recursive = 0;
  $this-set('rapportinis', $this-Rapportini-findAllByOfficeId($this-
Auth-user('office_id')));
}

This will work automagically.

hth
grigri

On Jan 20, 3:00 pm, tjr88 t...@timothyreynolds.co.uk wrote:
 Hi,

 I am quite new to cakephp and am having some issues with the following
 code,

 function findbyoffice($office = null) {
                 return $this-find('all',array('conditions' = 
 array('office_id' =
 $office)));
         }

 function index() {
         $this-Rapportini-recursive = 0;
         $this-set('rapportinis', $this-Rapportini-findbyoffice($this-Auth-

 user('office_id')));
 }

 it gives me,
  SQL Error: 1054: Unknown column 'Rapportini.office' in 'where
 clause' . . . WHERE `Rapportini`.`office` = '1'

 Now the SQL has clearly dropped the _id section of the field.

 What have i done wrong??

 Thanks
 Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Issues with conditions in view

2009-01-20 Thread grigri

If you want to use the paginator, you have to use the paginate
function, not a naked find [well, you _could_, but it would be very
finnicky].

Try this:

class YourController extends AppController {
  var $paginate = array(
'Rapportini' = array(
  'recursive' = 0,
  'limit' = 20 // or whatever
)
  );

  function index() {
$this-set('rapportinis', $this-paginate('Rapportini',
  array('Rapportini.office_id' = $this-Auth-user('office_id'))
));
  }
}

That should give you what you want.

hth
grigri

On Jan 20, 3:57 pm, tjr88 t...@timothyreynolds.co.uk wrote:
 Thats great :-)

 But i know get
  Undefined variable: paginator [APP\views\rapportinis\index.ctp, line
 5]

 Fatal error: Call to a member function counter() on a non-object in C:
 \xampp\htdocs\projects\rapportini\app\views\rapportinis\index.ctp on
 line 5

 which is because i use paginator() on the index.cpt page. i tried to
 add the function like so,
 $this-set('rapportinis', $this-Rapportini-findAllByOfficeId($this-

 Auth-user('office_id'),$this-paginate()));

 This only returns errors.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: delay or wait?

2009-01-16 Thread grigri

All databse queries are executed synchronously - i.e. once you call
`find()`, the next line of code will not execute until the find has
been completed, the data fetched and formatted.

If the returned data is not there, then there must be a problem with
your query. Using the sql query log (debug=2), check the sql and
results. Execute exactly the same sql directly in your database (mysql
console, phpminiadmin, phpPgAdmin, ...) and ensure that the results
are correct.

hth
grigri

On Jan 16, 10:45 am, forrestgump vikhya...@gmail.com wrote:
 Was wondering if there is a delay function i could use in my
 controller , to force cake to wait for a find() function to execute...
 This is the situation iam in

  $temp=$this-Invno-find('all',array('conditions'=''.
 $conditions,'fields'=array('id')));
  $this-data['invno_id']=0;
 $this-data['invno_id']=$temp[0]['Invno']['id'];

 Now i wish to execute this statement only after $this-data
 ['invno_id'] had been set
 $this-Invoice-save($this-data)

 but for some reason there is an observed delay and the program just
 halts

 i did this to check if there is a delay--
 $temp=$this-Invno-find('all',array('conditions'=''.
 $conditions,'fields'=array('id')));
  $this-data['invno_id']=0;
 $this-data['invno_id']=$temp[0]['Invno']['id'];

 if($this-data['invno_id']!=0)
 {
  $this-Invoice-save($this-data);}

 else
 {
  $this-Session-setFlash('There is a delay in getting the invno_id');
  $this-redirect('/invoices',null,true);

 }

 I keep getting the message There is a delay in getting the invno_id.
 Can someone help me with a workaround?

 Will appreciate any help...

 forrestgump
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Using a different path for image storage

2009-01-16 Thread grigri

I usually add this to my .htaccess files:

# Do not route missing asset requests through cake
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !img/titles
RewriteRule ^/?((img|js|css|swf)/.*)$ - [R=404,L]

The img/titles rule is an exception because those can be dynamically
generated through cake.

An incorrectly named img tag on a certain page played havoc with the
sessions during development; since then I take this approach, and my
desk is acquiring fewer and fewer head-shaped indentations.

hth
grigri

On Jan 16, 12:46 pm, Adam Royle a...@sleekgeek.com.au wrote:
 This error happens when the image doesn't exist, and the request is
 forwarded to cakephp. Make sure the file is there and case-sensitive
 if on linux.

 Cheers,
 Adam

 On Jan 16, 8:48 pm, g4b0 gabriele.bros...@gmail.com wrote:

  Hi all,
  I'm trying to put some images in /app/webroot/img/photo, but the
  following html doesn't display anything:

  img src=/img/photo/HawaiiSurf.jpg alt= /

  In addiction, if I point my broser directly 
  tohttp://mysite.com/img/photo/HawaiiSurf.jpg
  I get this:

  Missing Controller
  Error: ImgController could not be found.
  Error: Create the class ImgController below in file: app/controllers/
  img_controller.php

  ?php
  class ImgController extends AppController {

          var $name = 'Img';}

  ?

  How can I solve it?

  Thanks a lot
  g4b0
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Bakery Article Comment Notification broken

2009-01-15 Thread grigri

I noticed this too; In thunderbird the email content is blank. You
have to view source to actually see the content.

On Jan 15, 9:43 am, dr. Hannibal Lecter lecter...@gmail.com wrote:
 I have reported this a while ago:

 https://trac.cakephp.org/ticket/5001

 Still having the same problem.

 On Jan 15, 8:32 am, majna majna...@gmail.com wrote:

  I cant open mail notification in gmail.
  content type is multipart/alternative,
  message is attached as unknown file.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: PHP Page inside of Cake but not Cake

2009-01-15 Thread grigri

Sure, put the .php file inside the app/webroot folder.

eg: app/webroot/bacon.php

Then call http://server/bacon.php

hth
grigri

On Jan 15, 4:07 pm, Pyrite thelette...@gmail.com wrote:
 Is there a way to make a plain jane custom php page and access it
 inside of the cake directory but not have CakePHP interefere with it.
 I am wanting to test a page and CakePHP and is screwing up the java
 script and I want to test the page as if CakePHP wasn't there.

 However, I am at work and do not have a separate webspace to test php
 pages except the CakePHP app directory.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Label information for Multiple Checkboxes

2009-01-15 Thread grigri

You need to set the $displayField property inside your `Aliquot` model
to whatever field you want for the label.

On Jan 15, 4:47 pm, Tony Thomas truet...@gmail.com wrote:
 I'm building a list of checkboxes like so:

 echo $form-input('Aliquot.id', array( 'label' = FALSE,
                                                                               
   'type' = 'select',
                                                                               
   'multiple' = 'checkbox',
                                                                               
   'options' = $aliquots));
 echo $form-input('box_id', array('options' = $boxes));

 $aliquots above is built from $this-Aliquot-find('list', $options);
 which finds all the ids of the pertinent records. The problem I have
 this this only generates a list of ids. Is there good way to load an
 array for 'label' so that I can display more than just the list of ids?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problem on save operation

2009-01-14 Thread grigri

Do you have $cacheQueries set to true in the model? This would cause
this behavior.

Try adding `var $cacheQueries = false` in your model definition.

hth
grigri

On Jan 14, 8:53 am, marco.rizze...@gmail.com
marco.rizze...@gmail.com wrote:
 I paste my code:

 function edit($id=-1)
 {
    pr($this-data); // Original Passed Data

    ..

    $object=$this-Document-read(null,$id);

    .

    pr($this-data); // Data after read operation
    .

 }

 The original passed data is correct . (Example : $data['Document']
 ['title']='edited title');
 Instead in the data after read operation I get that there are the data
 that are read (Example : $data['Document']['title']='not edited
 title' ).

 On Jan 13, 6:07 pm, brian bally.z...@gmail.com wrote:

  It's not clear to me what you mean. Can you post an example of that
  part of your controller action?

  On Tue, Jan 13, 2009 at 6:21 AM, marco.rizze...@gmail.com

  marco.rizze...@gmail.com wrote:

   Hi
   I have this problem .
   I do a save operation on a model inside an action of my controller.
   If i do a read operation on the model of the ID object that I do to
   save later I get that the $this-data contains the data that I have
   read with read operation.
   I have made some errors or there are options to set to avoid this
   features?
   Many Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: validation message are not coming

2009-01-13 Thread grigri

You're mixing and matching cake ORM and raw mysql functions - not a
good idea. You're just _asking_ for trouble with that.

Just use bake to get a standard cakey add method, then add in your
bits and bobs. Most of the code in your controller would be better off
in the model, imho.

Also, long chunks code are formatted badly, and hard to read on the
google group. If the code is more than a few lines, use a pastebin
then post the link here.

 please tell me the answer it is very urgent

Sorry for being blunt, but the answer is to read the fine manual,
and saying your problem is very urgent is more likely to get it
ignored than dealt with.

hth
grigri

On Jan 13, 1:37 pm, mona poojapinj...@gmail.com wrote:
 In my add view when i kept all the fields blank and click on submit
 button it will display a message record added successfully instead of
 that i wan't to display my validation message and page should not be
 redirect to other page
 how to do this here is my add function code
 add function in
 controller---
 function add(){
 $this-set('sections', $this-Entry-Section-find('list',array
 ('fields'='Section.section','Section.id')));
 if (!empty($this-data)){
 $this-Entry-save($this-data);
 $id=mysql_insert_id();
 if($id){
 $query=mysql_query(select max(counter) from entries);
 $row=mysql_fetch_array($query);
 $co=$row[0]+1;
 $q=mysql_query(update entries set counter=$co where id=$id);
 if(is_uploaded_file($this-data['Entry']['File']['tmp_name'])){
 $fileData = fread(fopen($this-data['Entry']['File']['tmp_name'],
 r),
 $this-data['Entry']['File']['size']);
 $fname = $this-data['Entry']['File']['name'];
 $ftype = $this-data['Entry']['File']['type'];
 $fsize = $this-data['Entry']['File']['size'];
 $fdata = addslashes($fileData);
 $q1=mysql_query(update entries set name='$fname',size=
 $fsize,type='$ftype',data='$fdata' where id=$id);}
 }

 $this-Session-setFlash('The Entry has been saved');
 $this-redirect('/entries/index');}
 }

 -my model code is
 -
 ?php
 class Entry extends AppModel{
         var $name = 'Entry';
         var $belongsTo=array('Section'=array(
         'className'='Section'
         ),
         'Submenu'=array('className'='Submenu')
         );
         var $validate = array(
         'username' = array('/^[a-zA-Z._0-9]+$/'),
                 'Please enter username' = array('rule'='notEmpty'),
                 'Listitem'=array(
                   'Please enter listitem' = array
 ('rule'='notEmpty')),
                  'section_id'=array(
                   'Please select listitem' = array
 ('rule'='notEmpty')),
                 'Telephone'=array(
                   'Please enter phone number' = array
 ('rule'='notEmpty'),
                   'Must be at least 10 chars' = array('rule'=array
 ('minLength', 10))),

       );}

 ?

 please tell me the answer it is very urgent
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problem sorting with Containable, on models two levels deep

2009-01-13 Thread grigri

You could try looking at the linkable behavior:

http://rafaelbandeira3.wordpress.com/2008/11/16/linkable-behavior-taking-it-easy-in-your-db/

It looks promising, but I haven't used it (yet) and can't guarantee it
will handle your use case.

If not, you could re-bind manually to the deeper associations - I used
this technique on a project a few months ago and it worked fine.

$this-ModelA-bindModel(array('belongsTo' = array(
  'ModelCTemp' = array(
'className' = 'ModelC',
'foreignKey' = false,
'fields' = array('bacon'),
'conditions' =  'ModelCTemp.id = ModelB.foreign_id'
  ),
  'ModelDTemp' = array(
'className' = 'ModelD',
'foreignKey' = false,
'fields' = array('eggs'),
'conditions' =  'ModelDTemp.id = ModelC.foreign_id'
  )
)));
$results = $this-ModelA-find('all', array(
  'order' = 'ModelCTemp.bacon ASC, ModelDTemp.eggs DESC'
));

(The 'Temp' prefix is to avoid the other link results from overlapping
- I can't remember why this is an issue but it was at the time)

hth
grigri

On Jan 13, 3:01 pm, the_woodsman elwood.ca...@gmail.com wrote:
 Hi Bakers,

 These are my model relations, in general terms:

 [ModelA] belongsTo [ModelB] belongsTo [ModelC] belongsTo [ModelD]

 I'm calling ModelA-contain(...)

 In my contain I'm successfully retrieving fields all the way down to
 Model D.

 However, when it comes to ordering, I get errors when trying to order
 by fields in model C or D.

 Unknown column 'ModelC.field' in 'order clause'

 From the SQL, it's clear the problem is that models C and D are
 accessed via different,
 individual queries per model (Select `ModelC`.field FROM `ModelC`),
 and re-integrated into the results set, whilst the ordering statements
 are of course in the initial query.

 I'm around 1.2 RC2.

 Is this a known issue? Are there any solutions/work arounds? I really
 don't want to manually re-sort my data :(

 Thanks,

 Woody
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: BeforeSave and undefined index

2009-01-13 Thread grigri

You wrote this:

   $this-data['ArvcProfile']['minor_criteria'] == $minor;
$this-data['ArvcProfile']['major_criteria'] ==
$major;

if ($major  1 || ($major == 1  $minor  1) ||
($minor  3)) {
$this-data['ArvcProfile']
['criteria_fulfilled'] == 1;
}

I think you meant this:

   $this-data['ArvcProfile']['minor_criteria'] = $minor;
$this-data['ArvcProfile']['major_criteria'] = $major;

if ($major  1 || ($major == 1  $minor  1) ||
($minor  3)) {
$this-data['ArvcProfile']
['criteria_fulfilled'] = 1;
}

This sort of typo is frequent the other way around (using = instead of
==) and can lead to major hair loss. This way around, I haven't seen
so much

hth
grigri

On Jan 13, 4:51 pm, Kanten anders.ho...@gmail.com wrote:
 Hi,

 I'm trying to do some beforesave massaging in my model but it fails
 with the error messages:
 Notice (8): Undefined index:  minor_criteria [APP/models/
 arvc_profile.php, line 32]
 Notice (8): Undefined index:  major_criteria [APP/models/
 arvc_profile.php, line 33]
 Notice (8): Undefined index:  criteria_fulfilled [APP/models/
 arvc_profile.php, line 36]

 The threes indexes are not a part of the form, from which the data is
 derived, but are in the database table, and hence I thought I would be
 able to manipulate them in my model. My BeforeSave function can be
 seen below.

 Anyone know what I am doing wrong here.

 function beforeSave() {
                 /* Calculates no of major and minor ARVC criterias  */
                 $minor = 0;
                 $major = 0;
                 $total = 0;
                 $groups = array();
                 if($this-data['ArvcProfile']['rv_sev_dilatation'] == 1) 
 {$major++;}
                 if($this-data['ArvcProfile']['rv_aneurysms'] == 1) 
 {$major++;}
                 if($this-data['ArvcProfile']['rv_sev_seg_dilatation'] == 1) 
 {$major+
 +;}
                 if($this-data['ArvcProfile']['rv_mild_dilatation'] == 1) 
 {$minor++;
 $groups[]=1;}
                 if($this-data['ArvcProfile']['rv_mild_seg_dilatation'] == 1) 
 {$minor
 ++; $groups[]=1;}
                 if($this-data['ArvcProfile']['rv_reg_hypokinesia'] == 1) 
 {$minor++;
 $groups[]=1;}
                 if($this-data['ArvcProfile']['fibrofatty_replacement'] == 1) 
 {$major
 ++;}
                 if($this-data['ArvcProfile']['inverted_t_waves'] == 1) 
 {$minor++;
 $groups[]=3;}
                 if($this-data['ArvcProfile']['epsilon_waves'] == 1) 
 {$major++;}
                 if($this-data['ArvcProfile']['late_potentials'] == 1) 
 {$minor++;
 $groups[]=4;}
                 if($this-data['ArvcProfile']['lbbb_vt'] == 1) {$minor++; 
 $groups[]
 =5;}
                 if($this-data['ArvcProfile']['familial_disease'] == 1) 
 {$major++;}
                 if($this-data['ArvcProfile']['familial_sd'] == 1) {$minor++; 
 $groups
 []=6;}
                 if($this-data['ArvcProfile']['familial_history'] == 1) 
 {$minor++;
 $groups[]=6;}

                 $this-data['ArvcProfile']['minor_criteria'] == $minor;
                 $this-data['ArvcProfile']['major_criteria'] == $major;

                 if ($major  1 || ($major == 1  $minor  1) || ($minor  
 3)) {
                         $this-data['ArvcProfile']['criteria_fulfilled'] == 1;
                 }
                 return true;
         }

 /Anders
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Use mysql functions

2009-01-13 Thread grigri

class SomeModel extends AppModel {
  function beforeSave($options = array()) {
if (isset($this-data[$this-alias]['some_field'])) {
  $db = ConnectionManager::getDataSource($this-useDbConfig);
  $this-set('checksum', $db-expression('MD5(some_field)'));
}
  }
  return parent::beforeSave($options);
}

hth
grigri

On Jan 13, 4:27 pm, Shadows_Cl shadows...@gmail.com wrote:
 I need use mysql functions at some model. Ex. i have a table with 3
 fields,  id (int),  date_access (datetime), and checksum (varchar)...
 but, i need to apply MD5 (mysql) to field checksum when add a new row.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: share function in views

2009-01-12 Thread grigri

Put it in a helper, then use the helper in each view.

On Jan 12, 10:51 am, Henrik Gemal henrikge...@gmail.com wrote:
 I have a custom html escape function that I like to be able to use in
 two views.
 What's the best way to share function between views?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: bug in Debugger?

2009-01-12 Thread grigri

Try logging the exact url that was requested each time - I had a
similar problem a while ago which was due to an incorrectly formatted
image tag - I just had

img src=img/something.png alt= /

On the /customers/login page this would end up generating a request
for

`/customers/login/img/something.png`

which was processed through the login action of the customers
controller, resulting in the method being called twice for each page
request.

This was driving me nuts until I looked at the actual request logs and
spotted the strange url.

hth
grigri

On Jan 12, 6:58 am, brian bally.z...@gmail.com wrote:
 more: I put this immediately inside add()

 die(debug($this-data));
 Debugger::dump($this-data);

 This dumps the data--intact--onto the page. When I comment out the
 die() line, I get:

 array(
         Record = array(),
         Discipline = array()
 )

 I can't see how this possibly could be a PEBCAK situation, though I'd
 be grateful just to figure this out.

 How the heck can the data be disappearing like this?!

 I realise this probably isn't a Debugger problem and I really should
 open a new thread, but Debugger sure isn't helping, in any case. That,
 and the repeated writes to the log make me wonder. But, all the same,
 with no Debugger calls, the data still goes bye-bye.

 HELP!

 On Mon, Jan 12, 2009 at 1:35 AM, brian bally.z...@gmail.com wrote:
  More on this: I put this in the controller:

  function beforeFilter()
  {
     die(debug($this-data));
  }

  So, when I submitted the form, all the data was right where it should
  be. (Obviously, I commented it to get the form to display). So, its
  disappearing act comes somewhere between beforeFilter() and add().
  I've been trying to hunt down the precise order of operations but have
  come up empty-handed. I know that I saw it somewhere once (it'd be
  nice if this was included in the Cookbook's A Typical CakePHP
  Request page). Is there anything between beforeFilter() and the
  controller's action??

  Before doing this, btw, there was no beforeFilter(). I've commented
  AppController::beforeFilter(). I commented the $components array.
  There's nothing in the model (nor AppModel) that would screw with the
  data.

  This was working earlier. Well, it was broken (it's early going) but I
  could debugger::log($this-data) just fine before. I must have done
  *something* to screw this up but, after staring at it for a couple of
  hours now, I'm absolutely fresh out of ideas.

  On Sun, Jan 11, 2009 at 11:40 PM, brian bally.z...@gmail.com wrote:
  I'm trying to debug a problem with one of my controllers where
  $this-data is (almost) empty (more on that in a sec) and so tossed a
  bunch of Debugger::log statements in the action. When I checked the
  debug.log I found that the entries are being repeated.

  The action starts out like this. I put several debugger statements in
  because I was trying to figure out what was happening to $this-data.

  public function add($media_type_slug = null)
  {
         $this-set('user_id', $this-Session-read('User.id'));

         debugger::log('controller -- first');
         debugger::log($this-data);
         ...
         // more stuff, and several other Debugger::log() statements

  debug.log:

  2009-01-11 23:17:17 Debug: controller -- first
  2009-01-11 23:17:17 Debug: null
  2009-01-11 23:17:19 Debug: controller -- first
  2009-01-11 23:17:19 Debug: null
  2009-01-11 23:17:21 Debug: controller -- first
  2009-01-11 23:17:21 Debug: null
  2009-01-11 23:17:50 Debug: controller -- first
  2009-01-11 23:17:50 Debug: array(
         Record = array(),
         Discipline = array()
  )
  2009-01-11 23:17:50 Debug: controller -- second
  2009-01-11 23:17:50 Debug: array(
         Record = array(),
         Discipline = array()
  )
  2009-01-11 23:17:50 Debug: controller -- third
  2009-01-11 23:17:50 Debug: array(
         Record = array(),
         Discipline = array()
  )

  The first 3 occur the first time I hit the action. $this-data is
  properly empty. What's weird, though, is that Debugger places 3
  entries, each 2 seconds apart, in the log.

  Now, when I submit the form at 23:17:50, I don't see that first one
  repeated. So, what's up with that? It can't be that Cake is running
  through the method 3 times the first time, can it? Because the other
  Debugger stateents are all inside an if(empty($this-data)) block.

  Anyway, besides all of that, as you can see, when the form is
  submitted, I'm only seeing the names of the 2 models used in the form,
  but no data at all. Anyone have any ideas on that? I'm well and truly
  stumped!

  The form is nothing special and looks like:

  echo $form-create('Record', array('action' = 'add', 'type' = 'file'));
  echo $form-hidden('Record.user_id', array('value' = $user_id));
  echo $form-hidden('Record.media_type_id', array('value' =
  $media_type['MediaType']['id']));
  echo $form-hidden('Record.media_type_slug', array('value' =
  $media_type['MediaType']['slug

Re: Simple Drop Down List

2009-01-12 Thread grigri

In your District model, add this line:

class District extends AppModel {
  var $displayField = 'district';
  // ...
}

Now use find('list') and it will work fine.

To avoid unnecessary code, you can just do this:

[controller]
$this-set('districts', $this-District-find('list'));

[view]
echo $form-input('district_id');

From this the `districts` variable will be used automatically to get
populate the dropdown. It's all in the naming!

hth
grigri

On Jan 12, 12:10 pm, forrestgump vikhya...@gmail.com wrote:
 Hello,
  Been a while since i posted herei ran into a problem and needed
 some help...I have two tables as follows:

 table1:
 name:districts
 fields:id,district

 table2:
 name:mandals
 fields:id,mandal,district_id

 as you might have guessed i have associated the two tables with the
 help of foreign key district_id. I manually entered the values and
 with the help of the values into the tables as:

 table1:
 id:1
 district:Nizamabad

 table2:
 id:1
 mandal:Bhongir
 district_id:1

 with the help of the belongsTo relationship as defined below

  var $belongsTo = array('District' =
                             array('className'  = 'District',
                                   'conditions' = '',
                                   'order'      = '',
                                   'foreignKey' = 'district_id'
                             )
                       );
 i was able to properly display the name of the district in a simple
 table in a view by using the code below
 table
         tr
                 thSno./th
                 thDistrict/th
                 thMandal/th
                 thAction/th
         /tr

         !-- Here is where we loop through our $mandals array, printing out
 mandal info --

         ?php $i=1; ?
         ?php foreach ($mandals as $mandal): ?
         tr
          td?php echo $i++; ?/td
          td?php echo $mandal['District']['district']; ?/td
          td?php echo $mandal['Mandal']['mandal']; ?/td
          td?php echo $html-link('Edit', /mandals/edit/.$mandal['Mandal']
 ['id']); ?/td
         /tr
         ?php endforeach; ?
 /table

 I wish to now create a form which contains the following fields and
 save the data into table2(mandals):
 Mandal Name:
 Districts:

 I want the Districts field to be a dropdown list which is populated
 with the name of the districts, but i want the corresponding id of the
 district to be stored in table2 district_id field when the save button
 is clicked.

 Will appreciate any help that can be offered ive been trying to figure
 something out since 3 days...i tried using:
 $this-set('districtslist', $this-District-find('list'));
 along with  echo $form-select('district_id',$districtslist,null,array
 (),'select one');

 but i end up populating the select list with the id's of the
 districts. by using
 $this-set('districtslist', $this-District-find('all'));
 the select list gets populated with the data of all the fields from
 both the tables.

 Please Help!!

 Thanks in advance,
 forrestgump
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-09 Thread grigri

Hi Jon,

Wow, you've really added quite a bit of functionality there. I
actually adapted some of the code I pasted yesterday from a tree
helper, so it's quite fitting. I was going to rewrite bits of my tree
helper anyway (to make it more generic) and this might help - thanks!

cheers
grigri

On Jan 9, 8:34 am, Jon Bennett jmbenn...@gmail.com wrote:
 Hi grigri,

 Thought you might like to see what I ended up with. It's not refined
 fully, but it does the job at the moment.

 helper:http://pastie.org/356423
 usage:http://pastie.org/356424

 Cheers the start point, super helpful!

 jon

 --

 jon bennett
 w:http://www.jben.net/
 iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



SW England Cake Meetup

2009-01-09 Thread grigri

Rather than completely hijack WebbedIT's thread, I'd thought I'd start
a new one.

It seems we have a few (so far...) bakers in or around the Southwest
who would be interested in a meetup. So let's plan one!

Location? Bath has been suggested; fine by me - it's a nice place and
not too far. How many for Bath? Anywhere else to suggest?

Venue? I'd suggest a pub; a lot of pubs here have function rooms that
can be booked for free, seems like the best solution for a non-techy
meetup.

So, let's plan...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: HABTM and field formatting issue [Need Suggestion]

2009-01-09 Thread grigri

The format of the `$results` array in `afterFind` varies, a lot,
depending on circumstance.

Your best bet is to do a debug($results) inside `afterFind` to see
exactly what structure the data is in and act accordingly. There was
another thread on this recently. Your `afterFind` code must cope with
the different array structures.

Other thread is here: 
http://groups.google.com/group/cake-php/browse_thread/thread/32ab9f8baed4a05a/062678e92b080f18

hth
grigri

On Jan 9, 3:21 pm, Ernesto e.fanz...@gmail.com wrote:
 Hello.

 i have 2 models, linked together by a HABTM relationship.
 The 2nd model has a function that formats some fields after the data
 is loaded.
 Why is this function not working if i load data from the HABTM
 relationship?
 is there any better way to make this work?

 Here's an example

 NOTE: this code is for example purpose only. Don't look @ typos :)

 class Car extends AppModel {
         var $name = Car;

         var $hasAndBelongsToMany = array(
                 Passenger = array(
                         className = Passenger
                 )
         );

 }

 class Passenger extends AppModel {
         var $name = Passenger;

         function afterFind($results, $primary = false) {
                 $results[Passenger][Name] = 
 strtoupper($results[Passenger]
 [Name]);
                 return $results;
         }

 }
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: exclude directory from routing

2009-01-05 Thread grigri

Just add this to your root .htaccess file [before the cake bit]

# Overrides
IfModule mod_rewrite.c
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?(clickheat)/(.*)$
RewriteRule ^.*$ - [L]
/IfModule
# Cake rewrites here
# ...

[Obviously you need to change 'clickheat' to the name of your
directory - or use `(clickheat|stats|bacon|eggs)` for multiple
directories]

hth
grigri

On Jan 5, 1:12 pm, Liebermann, Anja Carolin
anja.lieberm...@alltours.de wrote:
 Hi Marcus,

 I guess the proper setup for the whole thing would be to have the 
 CakePHP-Website and the other one in parallel folders and not the independent 
 one in a subfolder of the Cake-Website

 /
 |
 __cakesite
 |
 __other website

 Anja

 -Ursprüngliche Nachricht-
 Von: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] Im Auftrag 
 von eMarcus
 Gesendet: Montag, 5. Januar 2009 12:00
 An: CakePHP
 Betreff: exclude directory from routing

 Hi,

 On my cakephp testenvironment, I would like to exclude a specific directory 
 from any cakephp rerouting. That directory holds an independent website.

 However, when I try to access a page in that directory, cakephp tries to load 
 a controller that is called like the directory - which obviously fails

 Is there a way to exclude a directory tree from cake php?

 Thanks,

 bye
 me.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Benefits for $html-link

2009-01-05 Thread grigri

The main difference is reverse routing.

Defining a specific route syntax for a given controller/action and
using the array method will make the correct url.

Let's say you have

`Router::connect('/catalogue/c/*', array('controller' = 'categories',
'action' = 'view'));`
`Router::connect('/catalogue/p/*', array('controller' = 'products',
'action' = 'view'));`

Then you do

`$html-link('Link', array('controller' = 'products', 'action' =
'view', 123));`

The result will be `/catalogue/p/123`

Whereas if you do

`$html-link('Link', '/products/view/123')`

The result will be `/products/view/123`, which doesn't correspond to
your route.

hth
grigri

On Jan 5, 10:56 am, gearvOsh mileswjohn...@gmail.com wrote:
 Are there any benefits, or behind the scenes magic for doing this:

 $html-link('Link', array('controller' = 'users', 'action' =
 'login', 'var'));

 Compared to:

 $html-link('Link', '/users/login/var/');

 This also applies to anywhere else you build urls.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Updating a single database rows field

2008-12-18 Thread grigri

What about updateAll() ?

$this-User-updateAll(
  array('User.status' = 'active'),
  array('User.id' = 1)
);

Seems pretty straightforward to me...

On Dec 18, 7:12 am, gearvOsh mileswjohn...@gmail.com wrote:
 I still have yet to find a straight forward way to do this, so ill
 simply do something like this:

 function update($user_id, $fields) {
         if (is_array($fields)) {
                 App::import('Sanitize');
                 Sanitize::clean($fields);

                 $cleanFields = array();
                 foreach ($fields as $field = $value) {
                         $cleanFields[] = User.. $field . = '. $value .';
                 }

                 $sql = UPDATE users AS User SET . implode(', ', 
 $cleanFields) .
 WHERE User.id = . Sanitize::escape($user_id) . LIMIT 1;
                 return $this-query($sql);
         }

         return NULL;

 }
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: SQL syntax error when using comparison operators

2008-12-18 Thread grigri

No, the first one is the correct way; the manual is correct. You must
be using an old version of cake.

This was changed a while ago to avoid SQL injection.

On Dec 18, 12:24 pm, boyracerr benjamins...@gmail.com wrote:
 I have now solved this; correct syntax is:

 $this-data['user_count'] = $userObj-findCount(array(
                      'User.status' = '1',
                     'User.id' = '' . 18)
                 , 0);

 I believe this to be a fault in the documentation 
 athttp://book.cakephp.org/view/74/Complex-Find-Conditions- the fifth
 example down will not work unless modified as above.

 On Dec 18, 12:46 am, boyracerr benjamins...@gmail.com wrote:

  I'm trying to do a simple comparison search, and for some reason its
  giving me an error. I feel like I am missing something blindingly
  obvious, but the only thing that suggests itself at the moment is some
  sort of bug in the way that conditions are parsed.

  Doing the following:

  $this-data['user_count'] = $userObj-findCount(array(
                          'User.status' = '1',
                          'User.id ' = 18)
                  , 0);

  gives an SQL error, caused by this in the SQL:

  `User`.`id`  = 18

  (the space between  and = is the problem)

  Could anyone show me where I am going wrong?

  Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: validate and allow only specified fields

2008-12-18 Thread grigri

Built-in whitelisting:

$this-Post-save($data, array('fieldList' = array('field1',
'field2', 'field3')));

hth
grigri

On Dec 18, 1:29 pm, Henrik Gemal henrikge...@gmail.com wrote:
 Is there a way in the model to say that it should only be possible to
 submit these values in the post?

 I want to disallow the user posting any other form fields that I have
 specified in the model's validate array?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Controller action randomly running twice

2008-12-18 Thread grigri

Cake doesn't call the actions twice, normally.

I don't know if this is any help but I had a similar problem a while
ago. It was down to a normal image tag on the view template:

img src=img/whatver.png /

Called from /posts/edit/123, this resulted in a query for /posts/edit/
123/img/whatver.png which called the action again. Had to scan the
access logs for this one, it was driving me crazy.

A similar problem on another site (a css file this time, but the same
concept) messed up all of the sessions.

My solution (apart from fixing the offending tags) was to add this to /
app/webroot/.htaccess

# Do not route missing asset requests through cake
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !img/uploads/
RewriteRule ^/?((img|js|css|swf)/.*)$ - [R=404,L]

The 'uploads' one is the exception as it was dynamically generated, so
I needed normal cake handling. Everything else gets a 404 directly if
it doesn't exist.

On some Apache servers the [R=404] thing fails, so I created an
error.php in webroot containing `?php header(HTTP/1.0 404 Not
Found); ?` and changed the line to

RewriteRule ^/?((img|js|css|swf)/.*)$ error.php [L]

hth
grigri



On Dec 18, 1:30 pm, WebbedIT p...@webbedit.co.uk wrote:
 Could really do with some help with this.

 I added some log calls to my edit action and clicked to edit two
 different records, checked the log and found the following ...

 2008-12-18 13:25:57 Debug: Edit form displayed for record # 6815
 2008-12-18 13:25:58 Debug: Edit form displayed for record # 6815
 2008-12-18 13:27:42 Debug: Edit form displayed for record # 877
 2008-12-18 13:27:43 Debug: Edit form displayed for record # 877

 Why is CakePHP calling the actions twice?  Surely this is not normal
 behaviour?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: routing — duplicate content and SEO concerns

2008-12-17 Thread grigri

function demo($arg1, $arg2) {
  $args = func_get_args();
  $arg3 = $args[2];
}

On Dec 17, 3:44 pm, RyOnLife ryan.mckil...@gmail.com wrote:
 This issue has remained at the back of my mind, and I think I have a
 really simple solution. I need one question answered first:

 examples_controller.php has a function: demo($arg1, $arg2) { ... }
 call up this URL: /examples/demo/val1/val2/val3

 Inside the controller logic for demo(), how can I retrieve 'val3'?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: data validation for optional fields

2008-12-16 Thread grigri

It just so happens I was playing around with some code for exactly
this purpose. I stress that the code is proof-of-concept, and
definitely needs work and testing before being ready for prime time,
but by all means have a play:

http://bin.cakephp.org/view/1263511817

This was my usage:

class Address extends AppModel {
  var $name = Address;

  var $actsAs = array('ConditionalValidation');

  var $validate = array(
'postal_code' = array(
  array(
'required' = true,
'allowEmpty' = false,
'rule' = '/^.+$/',
'message' = 'You must enter a zip/postcode'
  ),
  array(
'on' = 'country=UK',
'rule' = array('postal', null, 'uk'),
'message' = 'You must supply a valid UK postcode'
  )
)
  );
}

(Everyone must enter a zip/postcode, but if the address is a UK one
then the postcode must be a valid uk postcode.)

The usage is simple - put an expression in the 'on' parameter. Various
operators are handled (see code). Every expression must be binary
(left op right).

The LHS and RHS can be in the following format:

double-quoted string = literal string
12345 = literal integer
3.1415927 = literal float
simple_field = $model-data[$model-alias][field]
other = first value extracted from $model-data with Set::extract()

hth
grigri


On Dec 16, 6:26 am, Markus markus.hardiya...@gmail.com wrote:
 if i set it required into false, would that means the secondary field
 can be empty?

 how do i check something like this:

 if (usesecondaryemail)
      validate secondary_email and secondary_email is not empty

 can the validation for this specific fields be check from controller?

 On Dec 16, 12:02 am, bingo ragra...@gmail.com wrote:

  hi Markus,

  Within your secondary email validation criteria, set required:false

  $this-validate = array(
       'primary_email' = 'email',
       'secondary_email' = array(
               'rule' = 'email',
              'required' = false,
             'message' = 'Please provide valid email address'
      )

  )

  On Dec 15, 10:55 am, Markus markus.hardiya...@gmail.com wrote:

   hello,

   currently I'm creating an user input form which in it have an optional
   fields but that fields must be filtered too if the user give check on
   a checkbox, here is the example of part pf the form:

   use secondary email: checkbox
   your secondary email: input text

   what i want to do is disable the input text as default, when the
   user give check on check box, the input text is activated and user
   must fill the input test with a valid email address (couldn't be
   empty).

   right now, i can do filtering on the email address using CakePHP
   filter, but how can i run the filter only when the user give check on
   use secondary email

   if the user doesn't give check on use secondary email then i don't
   need to store the email value (it will be NULL in the database)

   thank you
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model + foreign key problem

2008-12-16 Thread grigri

Based on your current database design, the easiest thing would be to
have a separate inbox/outbox:

class Message extends AppModel {
  var $belongsTo = array(
'Sender' = array('className' = 'User'),
'Receiver' = array('className' = 'User')
  );
}

class User extends AppModel {
  var $hasMany = array(
'SentMessage' = array('className' = 'Message', 'foreignKey' =
'sender_id'),
'ReceivedMessage' = array('className' = 'Message', 'foreignKey'
= 'receiver_id')
  );
}

If you need to fetch all sent and received for a user at the same
time, you'd do it manually

$messages = $this-Message-find('all', array(
  'conditions' = array(
'or' = array(
  'Message.sender_id' = $userId,
  'Message.receiver_id' = $userId,
)
  )
));

For different database designs there are other solutions, it all
depends on what you want to achiveve.

hth
grigri



On Dec 16, 3:56 am, Jnic jeannico...@gmail.com wrote:
 nobody ?

 On Dec 14, 6:57 pm, Adriano Varoli Piazza mora...@gmail.com wrote:

  On 14 dic, 19:52, Jnic jeannico...@gmail.com wrote:

   Hi,

   I'm doing a private message system for my website. I've created a
   database called messages, which contains :

   id,sender_id,reciever_id,subject,message,date

  Unrelated, but do note that 'reciever' is a typo: correct spelling is
  'receiver'. Spelling might bite you using Cake, as most of the
  automagic relies on correct name relationships.

  --
  Saludos
  Adriano
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: appmodel save returns true to data not in database

2008-12-16 Thread grigri

What SQL is being executed?

On Dec 16, 5:26 am, mike mwu...@gmail.com wrote:
 somehow, its getting to 'test2' in the controller, however, I don't
 see the data in the table!  I actually had this working in cake1.1 but
 updated to 1.2 changed htmlhelper to formhelper, and now it doesn't
 work!  any help appreciated.

 Thanks.

 database:
 CREATE TABLE users
 (
 id int NOT NULL AUTO_INCREMENT,
 /* ... some other fields here */
 about_me varchar(255),
 PRIMARY KEY (id)
 );

 model:
 class User extends AppModel
 {
     var $name = 'User';

     var $validate = array();

 }

 view:

 ? echo $form-create('User', array('action' = '/add')); ?

 ?php echo $form-textarea('User/about_me')?

 ?php echo $form-submit('Add'); ?

 ? //echo $form-end('Add User'); ?
 /form

 controller:
 ...
         function add() {
                 $this-log('in newuser_controller add()');
                 $this-User-create();
                 if(!empty($this-data)) {
                         $this-log($this-data);
                         $this-log('test1');
                         //If the form data can be validated and saved...
                         if($this-User-save($this-data)) {
                         $this-log('test2');
                         //Set a session flash message and redirect.
                                 $this-Session-setFlash(User Saved!);
                                 //$this-redirect('newuser/add');
                         }
                 }
         }
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Action-Specific Helpers

2008-12-16 Thread grigri

The best place to look for advice would be the core code itself. In
libs/controller/controller.php, at the end of the paginate() function,
it ensures that the paginator helper will be loaded with this code:

if (!in_array('Paginator', $this-helpers)  !array_key_exists
('Paginator', $this-helpers)) {
  $this-helpers[] = 'Paginator';
}

If that seems long-winded, add a method to AppController:

function useHelper($helper) {
  $helpers = func_get_args();
  foreach($helpers as $helper) {
if (!in_array($helper, $this-helpers)  !array_key_exists
($helper, $this-helpers)) {
  $this-helpers[] = $helper;
}
  }
}

Then in your action you can do

$this-useHelper('Textile', 'Javascript');

hth
grigri

On Dec 16, 1:31 pm, Rob Wilkerson r...@robwilkerson.org wrote:
 How should I add multiple action-specific helpers?  Originally I had:

 $this-helpers[] = 'Textile';

 When I wanted to include the Javascript helper for this action, I
 couldn't find the right syntax (if there is a right syntax) to do
 so. I want to retain the default helpers, too.  I've made it work
 using traditional PHP array syntax, but am wondering if that's going
 to cause me any problems down the line.  For now, at least, I have:

 array_push ( $this-helpers, 'Textile' );
 array_push ( $this-helpers, 'Javascript' );

 Total noob question, I know, but I _am_ a noob so it probably won't be
 the last time while I get a grip on what's possible and the best
 practices. :-)

 Thanks.

 Rob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Newbie question on form validating

2008-12-11 Thread grigri

Yes; Cake supports dynamic models.

If you don't create an actual model file, cake will instantiate an
instance of AppModel with the name and useTable set up to work
properly. This is only useful for basic models though as you can't
specify associations, behaviors, validation or anything specific for
the auto-model.

Its main use is for join tables in HABTM.

hth
grigri

On Dec 11, 11:29 am, AJV [EMAIL PROTECTED] wrote:
 A small typo - the path to the model file is of course /app/models/.

 BUT I just noticed that I can change the model file to whatever, even
 remove it, and it still works. Is this normal?!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Using Model in Custom Component

2008-12-10 Thread grigri

You've written condition where it should be conditions

On Dec 10, 8:47 am, jjh [EMAIL PROTECTED] wrote:
 I had to setup a find query inside my custom component but the find
 method doesn't seem to like my conditions array. Can anyone tell me
 what's wrong?

    public function test($id) {
       $userInstance = ClassRegistry::init('User');
       $param = array(
          'condition' = array(User.id=$id),
          'recursive' = -1
       );
       $user = $userInstance-find('all',$param);
       print_r($user);exit;
    }

 The result is always the entire data set.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



  1   2   3   4   5   6   >