Override behavior method?

2012-06-28 Thread Poyan Nabati
From the manual: 

Behavior methods are automatically available on any model acting as the 
behavior. For example if you had:
?php
class Duck extends AppModel {
public $name = 'Duck';
public $actsAs = array('Flying');
}
You would be able to call FlyingBehavior methods as if they were methods on 
your Duck model. When creating behavior methods you automatically get 
passed a reference of the calling model as the first parameter. All other 
supplied parameters are shifted one place to the right. For example:
?php
$this-Duck-fly('toronto', 'montreal');

What happens if Duck already has a method fly()?  

Do you 

   - get an error?
   - run the Models fly()-method?
   - run the Behaviors fly()-method?

Or formulated differently; 
With an attached behavior, can I still override certain methods with local 
implementations?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Override behavior method?

2012-06-28 Thread Poyan Nabati
Excellent. 

Thank you. 

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Routes vs Type checking for Action Parameters, best practice?

2012-06-28 Thread Poyan Nabati
Lets say I have a controller Books with an action view() defined as 
follows: 

class BooksController extends AppController {

public function view($id) {

// something

}

}

Let's assume that $id is supposed to be of a numeric type. 

I see two options; 

1) Setup the route so that it only connects for instance 
books/view/{integer} to  Books-view($id)
2) Have general routing like the defaults in CakePHP and include code in 
view() to make sure that $id is set and is numeric. 

Which is better practice? 

In my view I think the former is cleaner and less magicky. This is 
something I enjoyed working with the Play Framwork, that you explicitly had 
to connect a route to each action. 

What is your opinion?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Routes vs Type checking for Action Parameters, best practice?

2012-06-28 Thread Poyan Nabati
That's another type of error though. It's something have to handle in your 
application but I don't see the relation to my OP. 

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Routes vs Type checking for Action Parameters, best practice?

2012-06-28 Thread Poyan Nabati
I think you're not using routes in their purest form (to route stuff in 
the right way - rather than error trapping. 

Thing is, if you haven't supplied an integer, then there's really no 
matching action for the URL you've requested. I think that's completely in 
line with the purpose of routes. 

That is, if you supply a non-integer, then you haven't really matched any 
existing action, so you're redirected to an error or a default page.

Since PHP doesn't really have strict typing, maybe I could settle for if 
you haven't passed the right number of parameters, there's no matching 
action.

Why do that in two places?

I think it could result in cleaner code since you can be sure of the type 
and amount of input you receive in each action.

Don't you agree?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Slightly different models, merge or separate?

2012-06-26 Thread Poyan Nabati
Anyone?

On Monday, June 25, 2012 10:12:43 AM UTC+2, Poyan Nabati wrote:

 I have a question regarding more the design of the back-end rather than 
 specifically how to implement it. 

 I'm creating a life tracker of sorts. The purpose is to have a single 
 application to help you keep track of things that are important to you long 
 term.

 I want to be able to track a wide array of different things.

 For instance;


- What type of exercise did I do? (Fixed: Gym, Running or Other)
- Did I meditate today? (Boolean measurement)
- What was my weight today? (Numeric measurement)
- What's one good thing about today? (String measurement)

 So for each goal you have a single specific type of measurements.

 *How should I implement this on the backend?*


- *Two models.* I thought of having two models, Goal and Measurement, 
where Measurement has a corresponding field in the database called value 
that's agnostic of it's contents (in other words, a VARCHAR that I 
interpret differently depending on context). I believe, however, that this 
approach will create a lot of special code for each of the different cases 
down the line. 
- *Many models.* Another way to do it would be to create 
NumericMeasurement, BooleanMeasurement etc etc for each of the different 
measurement-types. In Goal I could have a field that indicates the type 
 and 
create the association Goal hasMany (each of the measurement types). Do 
 you 
see any problems with this approach?

 Is there another, better approach that I haven't thought about?

 How would you solve this?


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Advice about design.

2012-06-26 Thread Poyan Nabati
I feel like this is a good match for 
ACLhttp://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html,
 
you should check it out!

On Tuesday, June 26, 2012 7:44:45 PM UTC+2, Janne Johansson wrote:

 Hello!

 I am pretty much a complete newbie in regards to Cake, so I am looking for 
 advice on how to best go abpuit the design of an app.

 Basically, I have a structure where i have:

 Users that hasMany Accounts. 
 Accounts hasMany transactions.

 No magic there... But, I want a model where a User can assign read access 
 to their accounts to another user. And I wonder how to best acheive that 
 within the framework?

 I thought about a HABTM between users and acounts, but that seem a bit 
 messy?


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Slightly different models, merge or separate?

2012-06-25 Thread Poyan Nabati


I have a question regarding more the design of the back-end rather than 
specifically how to implement it. 

I'm creating a life tracker of sorts. The purpose is to have a single 
application to help you keep track of things that are important to you long 
term.

I want to be able to track a wide array of different things.

For instance;


   - What type of exercise did I do? (Fixed: Gym, Running or Other)
   - Did I meditate today? (Boolean measurement)
   - What was my weight today? (Numeric measurement)
   - What's one good thing about today? (String measurement)
   
So for each goal you have a single specific type of measurements.

*How should I implement this on the backend?*


   - *Two models.* I thought of having two models, Goal and Measurement, 
   where Measurement has a corresponding field in the database called value 
   that's agnostic of it's contents (in other words, a VARCHAR that I 
   interpret differently depending on context). I believe, however, that this 
   approach will create a lot of special code for each of the different cases 
   down the line. 
   - *Many models.* Another way to do it would be to create 
   NumericMeasurement, BooleanMeasurement etc etc for each of the different 
   measurement-types. In Goal I could have a field that indicates the type and 
   create the association Goal hasMany (each of the measurement types). Do you 
   see any problems with this approach?

Is there another, better approach that I haven't thought about?

How would you solve this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Including an element many times in a page

2012-06-25 Thread Poyan Nabati
This question is more about code design / code smell than a practical 
solution. 

I have a page where I list some tabular data. 

*Is it poor design to store the presentation of a single row in an element, 
and then for each row in that table display that element, passing different 
data to it each time?*

I'm not sure how Cake handles it behind the curtains, will it create a 
significant performance hit? One of the reasons I thought it was a good 
idea was that then I could dynamically load new rows using ajax and just 
call that element.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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