Re: Model/controller naming question - object name ends in 's' :

2008-01-14 Thread J.B.

If you specify $this-name in the model and controller, and the
variable $this-useTable in the model, you can use which names of the
database table, model and controller you'd ever want, without using
custom inflection.

E.g. I have a database table named news with the model named News
and the controller named NewsController...

On Jan 12, 11:08 pm, Tim [EMAIL PROTECTED] wrote:
 Hi all,

 I'm a newbie to CakePHP, and a relative newbie to php. CakePHP looks
 like just what I was looking for :)

 The issue is with business objects that end with the character 's'. I
 have a model that i'd like to call lens. That would make the
 controller called lenss_controller, which is only a problem because
 it appears in the URL. It would also mean a database table called
 lenss. Is there a way to give everything sensible names?

 Right now my solution is to call the model len, the controller
 lens_controller, and the database table lens.

 Thanks

 Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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: Problem with custom routes

2008-01-06 Thread J.B.

I still have my problem, and when I print the content of $this-params
with: pr($this-params) in the app_controller, the $this-
params['week'] and $this-params['year'] still contains the same
value (the week value).

I have managed to access the year value with $this-params['pass'][0],
but I don't like that solution...

The custom regular expressions is working as expected, because when I
go to the url i.e. /week/2/20008 it returns an error (because of the
incorrect year value).

On 6 Jan, 12:30, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I solved my problem, it was because I have a function __construct in
 my app_controller, and I'm checking $this-params['language'] in the
 function __construct.

 Moved code to app_controller beforeFilter, and $this-

 params['language'] is set.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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
-~--~~~~--~~--~--~---



Problem with custom routes

2008-01-05 Thread J.B.

Hello!
I have a problem with a custom route and accessing the info with $this-
params...
My route look like this:
Router::connect('/week/:week/:year', array('controller' = 'dates',
'action' = 'week','week' = null, 'year' = null), array('year' =
'([12][0-9]{3})', 'week' = '([1-9]|[1-4][0-9]|5[0-3])'));
As you can see the week and year is optional...
In the week-action in the DatesController I try to access the week and
year with $this-params['week'] and $this-params['year']. When I go
to the url i.e. /week/2/2008, both the params get the value of the
week (2, in this case)... Why is that? Does anyone have a clue?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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: Am I trying to do the impossible (or impractical)?

2007-12-01 Thread J.B.

As I said in my first post: just remember to name the associations
different names ...
I prefer this method over Rhee's suggestion with a bool for the
default address in the database... I think it looks nicer and feel
more OO :)

On Dec 1, 1:37 pm, AD7six [EMAIL PROTECTED] wrote:
 On Dec 1, 7:53 am, FrenchEscapes [EMAIL PROTECTED] wrote:



  Well that kind of worked!

  I have put:

  var $hasMany = array(
  'Address' = array('className' = 'Address',
 'foreignKey' = 
  'customer_id'
  ),
  );

  var $belongsTo = array(
  'Address' = array('className' = 'Address',
 'foreignKey' =
  'default_address_id',
   ),
  );

 It's doing it because with the same name the multi dimensional array
 of hasMany Addresses is being added to/merged with the result of your
 belongsTo Address.

 Change the name of one of those aliases (e.g. 'Address' change to
 'DefaultAddress').

 hth,

 AD

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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: Am I trying to do the impossible (or impractical)?

2007-11-29 Thread J.B.

zonium: yes, you're absolutely right. and I haven't tested it...
Remember to put two associations in the address model as well, address
hasOne (or hasMany, depending on what you want) customer
(default_address_id) and address belongsTo customer...

On 29 Nov, 10:27, zonium [EMAIL PROTECTED] wrote:
 I think your setup is not impractical, in fact it's a very common type
 of relationships, for example:
 User hasMany Address, and there is one Address that is used as
 default
 Theme hasMany Layout, and there is one Layout that is set as current
 etc.
 Using array as Christopher suggested is a solution I often use, but
 specifying an additional association as J.B. described seems to be a
 better solution.
 However, the association should be 'belongsTo' instead of
 'hasOne' (not sure if J.B. has tested)
 The reason is default_address_id' is foreign_key in customers table,
 and it corresponds to address_id on addresses table.

 in the Customer model, try
 $belongsTo = array(
 'Address' = array('className' = 'Address',
 'foreignKey' 
 = 'default_address_id',
  ),
 );

 in the controller, try:

 $this-Customer-findAll(array(id='123456'))

 and you will see the default address followed by an array of addresses
 (including the default address as well !)

 Zonium

 On Nov 28, 3:55 pm, J.B. [EMAIL PROTECTED] wrote:

  This can be done by adding another association, hasOne, on the model.
  The customers model will then have one hasOne and one hasMany
  association to the same model (addresses), just remember to name the
  associations different names and to use default_address_id as the
  foreign_key for the hasOne association.
  Code:
  var $hasMany = array('Address' = array('name' = 'Address'));
  var $hasOne = array('DefaultAddress' = array('name' = 'Address',
  {foreign_key stuff here...}));

  I think it's something like that :P

  On 29 Nov, 00:02, FrenchEscapes [EMAIL PROTECTED] wrote:

   I have a customers table and an addresses table, customers hasMany
   addresses, that bit's easy.

   But I want each customer to have a default address in the addresses
   table. I have a field 'default_address_id' in the customer table. I
   just can't get my head around how to use associations to link them.

   Thank you in advance.

   Duncan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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: Am I trying to do the impossible (or impractical)?

2007-11-28 Thread J.B.

This can be done by adding another association, hasOne... Then the
customers model will have both a hasMany and a hasOne association to
the same table (addresses). Only remember to specify that
default_address_id is the foreign_key for the hasOne association...
I think it's something like that :)

// J.B.

On 29 Nov, 00:02, FrenchEscapes [EMAIL PROTECTED] wrote:
 I have a customers table and an addresses table, customers hasMany
 addresses, that bit's easy.

 But I want each customer to have a default address in the addresses
 table. I have a field 'default_address_id' in the customer table. I
 just can't get my head around how to use associations to link them.

 Thank you in advance.

 Duncan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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: Am I trying to do the impossible (or impractical)?

2007-11-28 Thread J.B.

This can be done by adding another association, hasOne, on the model.
The customers model will then have one hasOne and one hasMany
association to the same model (addresses), just remember to name the
associations different names and to use default_address_id as the
foreign_key for the hasOne association.
Code:
var $hasMany = array('Address' = array('name' = 'Address'));
var $hasOne = array('DefaultAddress' = array('name' = 'Address',
{foreign_key stuff here...}));

I think it's something like that :P

On 29 Nov, 00:02, FrenchEscapes [EMAIL PROTECTED] wrote:
 I have a customers table and an addresses table, customers hasMany
 addresses, that bit's easy.

 But I want each customer to have a default address in the addresses
 table. I have a field 'default_address_id' in the customer table. I
 just can't get my head around how to use associations to link them.

 Thank you in advance.

 Duncan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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
-~--~~~~--~~--~--~---