Re: Components vs Helpers vs Utilities

2013-01-25 Thread lowpass
On Fri, Jan 25, 2013 at 4:53 PM, tron  wrote:
> Im trying to wrap my head around utilzing some functionality at all levels
> of MVC. Right now, I'm writing a component that performs several date
> functions for my app (the date utility is insufficient for what Im doing).
> The problem is I need the these functions in both my models and views as
> well. I'd imagine writing my own Utility is the best option as it can be
> used anywhere but they seem "off limits" as they are only contained within
> the Lib. I also cant find any information on writing a Utility. Yes, I could
> just go write one and add it to Lib/Utilities but I'm looking for some
> feedback on this issue as I've faced it several times. If you need to share
> functionality between all layers of the MVC, is using utilities the only way
> to do it without having to load a component/helper/behavior on the fly?

If CakeTime doesn't have what you want you could extend it.

app/Lib/Utility/MyTime.php :

App::uses('CakeTime', 'Utility');

class MyTime extends CakeTime {

public function foo($bar = null) {

}
}

In your controller/Model/View :

App::uses('MyTime', 'Utility');

...

$foo = MyTime::foo($bar);

But if all you want/need is a plain function (ie. no class) you could
just put in bootstrap.php

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

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




Re: Validating multiple fields problem

2013-01-25 Thread lowpass
On Fri, Jan 25, 2013 at 4:04 PM, Michael Gaiser  wrote:
> So, I have an event model that you are able to assign people to. Some events
> require at least 2 people to be assigned before they are considered valid. I
> have two fields for the user to filling in the persons name, and a custom
> validation rule that accesses $this->Event->data to loop through the
> different fields. This works great the first time through as the data is
> there, but it then fails a 2nd time (still within the same validation call)
> because $this->Event->data is now empty.  So here are my questions:
>
> Is there a better way to get the data from the other fields in the Event
> form?
> Why is $this->Event->data being cleared midway through the validation rule?
> Why does the custom validation function get run twice, failing the 2nd time?
> Is there some flag I need to set to make the validation only run once?
> Can I access Session data from within my model?

I think it might be best if you posted some code.

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

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




Re: Components vs Helpers vs Utilities

2013-01-25 Thread Michael Gaiser
I am having difficulty thinking of a time when I would need the same
function to be called in my model and my view. On my current project, I am
also needing to manipulate my dates as I have a non standard way of saving
them in the database. What I have done is manipulated them in the
controller using a Component so these functions can used in different
controllers. I get the data from the model, use the functions in
my component to manipulate the data and then pass that to the view, which
displays it as is.

Is that similar to what you are trying or am I misunderstanding your goals?

~Michael

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

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




Components vs Helpers vs Utilities

2013-01-25 Thread tron
Im trying to wrap my head around utilzing some functionality at all levels 
of MVC. Right now, I'm writing a component that performs several date 
functions for my app (the date utility is insufficient for what Im doing). 
The problem is I need the these functions in both my models and views as 
well. I'd imagine writing my own Utility is the best option as it can be 
used anywhere but they seem "off limits" as they are only contained within 
the Lib. I also cant find any information on writing a Utility. Yes, I 
could just go write one and add it to Lib/Utilities but I'm looking for 
some feedback on this issue as I've faced it several times. If you need to 
share functionality between all layers of the MVC, is using utilities the 
only way to do it without having to load a component/helper/behavior on the 
fly?
Thanks

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

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




Validating multiple fields problem

2013-01-25 Thread Michael Gaiser
So, I have an event model that you are able to assign people to. Some
events require at least 2 people to be assigned before they are considered
valid. I have two fields for the user to filling in the persons name, and a
custom validation rule that accesses $this->Event->data to loop through the
different fields. This works great the first time through as the data is
there, but it then fails a 2nd time (still within the same validation call)
because $this->Event->data is now empty.  So here are my questions:


   - Is there a better way to get the data from the other fields in the
   Event form?
   - Why is $this->Event->data being cleared midway through the validation
   rule?
   - Why does the custom validation function get run twice, failing the 2nd
   time?
   - Is there some flag I need to set to make the validation only run once?
   - Can I access Session data from within my model?

Thanks.

~Michael

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

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




Re: Any way to check url before redirect?

2013-01-25 Thread lowpass
On Fri, Jan 25, 2013 at 7:07 AM, LDSign  wrote:
> Thank you :) Thats a good starting point, but how do I check there if
> the redirect will be successfull?

It depends on what these URLs are pointing to. Are they all defined in
routes.php? Check Router::routes and compare. Do you have static
pages? Parse the $url (array or string) and check that the ctp file
exists. Are your pages instead in the DB? Again, parse $url and check
if the target exists.

If doing the latter, you really should have a cache file containing
all your page routes and have Router connect to them all, so this
should be covered by the first option.

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

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




Re: Simple Poll

2013-01-25 Thread lowpass
On Thu, Jan 24, 2013 at 9:14 PM, Advantage+  wrote:
> I need to create a simple poll for users and stumped on saving the results
> when user submits the poll.
>
> Poll hasMany Question
>
> Poll hasMany Result
>
> Question hasMany Choice

This is how I did it:

Poll
hasMany PollQuestion
PollOption
belongsTo PollQuestion
hasMany PollVote
PollVote
belongsTo PollOption

The only model that needs to be directly associated with Poll is
PollQuestion. The others chain together.

> Pretty simple, but how do you save the results since viewing the poll
> creates a form to save Poll?
>
>
> View the poll/$id pulls all the questions and choices for each, but how /
> where to save the results?
>
> What would be the correct table for this? poll_results? results?
>

Save the result in poll_votes. I made my PollsController handle
everything. In the vote() action:

$this->Poll->PollQuestion->PollOption->PollVote->save()

The table only requires id, poll_option_id, and user_id columns, but
should include created as well.

In Poll::afterFind(), loop through the various questions, then each of
its options, summing the number of votes for each. Add a new 'total'
key in the data array with the results.

foreach($data as $k => $d)
{
if ( isset($d['PollOption']) && isset($d['PollOption'][0]['PollVote']) )
{
$data[$k][$this->alias]['total'] = 0;

/* sum individual and grand total of votes
 */
foreach($d['PollOption'] as $j => $option)
{
$total = sizeof($option['PollVote']);

$data[$k]['PollOption'][$j]['total'] = $total;
$data[$k][$this->alias]['total'] += $total;
}

/* get percentage only if not multiple select
 */
foreach($data[$k]['PollOption'] as $j => $option)
{   
$per_cent = $option['total'] > 0
? floor( ( $option['total'] * 100 ) / 
$data[$k][$this->alias]['total'])
: 0;

$data[$k]['PollOption'][$j]['per_cent'] = $per_cent;
}
}
}

The "multiple select" thing is because some questions nneded to be
multiple choice. And therein was the cause of much grief, as I recall.

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

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




Re: Can't validate URL

2013-01-25 Thread Luciano Bargmann
My advise: Use http://yourls.org/

On Thursday, January 24, 2013 4:45:50 PM UTC-7, gonzela2006 wrote:
>
> Hello euromark,
>
> Thanks for your reply
> I'm trying to make my own short link service for my blog and I wish to 
> make it using CakePHP
> I think I can't validate this URL because it is too long
> *Note*:
> I have tried to encode this URL before validate it and still getting false 
> URL.
>
> Please advise
>
>

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

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




Re: Any way to check url before redirect?

2013-01-25 Thread LDSign
Thank you :) Thats a good starting point, but how do I check there if
the redirect will be successfull?

Frank

On Jan 25, 11:48 am, euromark  wrote:
> Use a component and its beforeRedirect() callback
> see the docs for more infos, but basically you can intercept the redirect
> this way.
>
> Am Freitag, 25. Januar 2013 11:28:37 UTC+1 schrieb LDSign:
>
>
>
>
>
>
>
>
>
> > Hi
>
> > I am searching for a way in cake to check an url before it is called
> > (via redirect).
>
> > Real world:
>
> > The user could set a custom start page to which he is redirect after
> > login. This page is mapped to "/" all the time too. So far so good :)
> > Unfortunately it is not predictable that this page is available in the
> > future (deleted or just because he has no rights to access this page
> > anymore). Of course this results in an error or even worse in a
> > redirect loop.
>
> > What I like to do is to check the given url for accessibility and if
> > it is not available redirect the user to a default page (which is
> > always accessible).
>
> > Can this be achieved with cake?
>
> > Thanks,
> > Frank

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

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




Re: Any way to check url before redirect?

2013-01-25 Thread euromark
Use a component and its beforeRedirect() callback
see the docs for more infos, but basically you can intercept the redirect 
this way.


Am Freitag, 25. Januar 2013 11:28:37 UTC+1 schrieb LDSign:
>
> Hi 
>
> I am searching for a way in cake to check an url before it is called 
> (via redirect). 
>
> Real world: 
>
> The user could set a custom start page to which he is redirect after 
> login. This page is mapped to "/" all the time too. So far so good :) 
> Unfortunately it is not predictable that this page is available in the 
> future (deleted or just because he has no rights to access this page 
> anymore). Of course this results in an error or even worse in a 
> redirect loop. 
>
> What I like to do is to check the given url for accessibility and if 
> it is not available redirect the user to a default page (which is 
> always accessible). 
>
> Can this be achieved with cake? 
>
> Thanks, 
> Frank 
>

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

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




Any way to check url before redirect?

2013-01-25 Thread LDSign
Hi

I am searching for a way in cake to check an url before it is called
(via redirect).

Real world:

The user could set a custom start page to which he is redirect after
login. This page is mapped to "/" all the time too. So far so good :)
Unfortunately it is not predictable that this page is available in the
future (deleted or just because he has no rights to access this page
anymore). Of course this results in an error or even worse in a
redirect loop.

What I like to do is to check the given url for accessibility and if
it is not available redirect the user to a default page (which is
always accessible).

Can this be achieved with cake?

Thanks,
Frank

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

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




Re: Which version is good and stable for development among 2.3.0 Rc2 and 2.2.5

2013-01-25 Thread euromark
You can probably safely start with 2.3 now.
By the time your app will be ready for deployment chances are pretty high 
2.3 will not be a RC anymore.
But in my experience, even RCs are pretty pretty close to the real deal, as 
there is a huge test coverage proofing that
2.3 is nothing less than an improved 2.2 (and at least as trustworthy).

Also - the 2.x documentation is fully adjusted to 2.3. So if you start with 
Cake now, you can not only leverage all the new stuff, you also
(most likely) got the most accurate documentation.


Am Freitag, 25. Januar 2013 10:21:05 UTC+1 schrieb Mariano C.:
>
> I will not set up a production environment with a release candidate, even 
> if it is at the second step (then really near to a stable)!
>
> Il giorno venerdì 25 gennaio 2013 05:32:33 UTC+1, anjith ha scritto:
>>
>> Hi,
>>  
>> New to cakephp. Just about to start development of new project using 
>> cakephp. Which version is good and stable for development among 2.3.0 Rc2 
>> and 2.2.5. 
>>  
>>  
>> Regards,
>> Anjith Kumar G
>>
>

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

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




Re: Which version is good and stable for development among 2.3.0 Rc2 and 2.2.5

2013-01-25 Thread Mariano C.
I will not set up a production environment with a release candidate, even 
if it is at the second step (then really near to a stable)!

Il giorno venerdì 25 gennaio 2013 05:32:33 UTC+1, anjith ha scritto:
>
> Hi,
>  
> New to cakephp. Just about to start development of new project using 
> cakephp. Which version is good and stable for development among 2.3.0 Rc2 
> and 2.2.5. 
>  
>  
> Regards,
> Anjith Kumar G
>

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

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