Monday, February 28, 2011

Re: Can't Save to DB

Ryan:
Per the CakePHP Book, saveAll() has two variations (http://
book.cakephp.org/view/1031/Saving-Your-Data):

"For saving multiple records of single model, $data needs to be a
numerically indexed array of records like this:"

and

"For saving a record along with its related record having a hasOne or
belongsTo association, the data array should be like this:"

so theweirdone's latest changes in message #5 seems appropriate for
what he's describing. And the function desription for create() is also
on the same page, preceded with an info box indicating:

"When calling save in a loop, don't forget to call create()."

theweirdone:
If you don't already have debug set to development mode (i.e.
Configure::write('debug', 2); ), do so while you are still writing the
code (change this to zero when you deploy to production, though).
With debug set to > 0, the SQL statements that are being issued
against the database should be listed below the "normal" rendered
page. If it's not listing any INSERTs into your episodes table, it
could very well be that the data is failing your model validation.
For example, are you using the 'date' core validation rule on the
'date' column (default format is 'ymd', and your sample data is
'mdy')?

Slightly off-topic: your code includes the following lines:
$show = $this->requestAction('/shows/getTvById/'.$id); //gets the
tv.com url
$episodes = $this->scrape($show, $id); //scrapes tv.com for the
show

I am assuming that Show hasMany Episode and Episode belongsTo Show and
that the column name containing the tv.com url is 'url'. If so, you
might want to consider the following instead:
$show = $this->Episode->Show->findById($id, array('id', 'url')); //
gets the tv.com url
$episodes = $this->scrape($show); // scrapes tv.com for the show

By using the requestAction() method, CakePHP has to go through the
Router (to determine which plugin/controller/action needs to be
called), then Dispatcher (to set up the controller and model(s)/
component(s)/etc), then the ShowController to run the getTvById()
action, which ultimately will execute some variant of $this->Show-
>find(). That's a lot of overhead that you can bypass by executing
the find() directly on the Show model (related to the Episode model
which is already loaded by the current controller, hence accessible as
$this->Episode->Show). And if the return value contains both the id
and url, your scrape method would only need one parameter instead of
two.


On Feb 28, 12:48 pm, Ryan Schmidt <google-2...@ryandesign.com> wrote:
> On Feb 28, 2011, at 14:23, theweirdone wrote:
>
>
>
>
>
> > I've changed my code, here's the new controller:
>
> > function addAll($id = null) {
> >         if (!$id) {
> >             $this->Session->setFlash(__('Invalid show id entered', true));
> >             //$this->redirect('/episodes');
> >         }
> >         $show = $this->requestAction('/shows/getTvById/'.$id); //gets the tv.com url
> >         $episodes = $this->scrape($show, $id); //scrapes tv.com for the show
> >         $this->set('episodes', $episodes); //sets $TVshowInfo for the view
> >         if($this->Episode->saveAll($episodes['Episode'])){
> >             $this->Session->setFlash(__($count.' episodes were saved.', true));
> >         }
> >     }
>
> > I've also updated the scraper to return the array such as in the manual:
>
> > Array
> > (
> >     [Episode] => Array
> >         (
> >             [0] => Array
> >                 (
> >                     [name] => Stowaway
> >                     [number] => 17
> >                     [description] => No synopsis available. Write a synopsis.
> >                     [date] => 3/18/2011
> >                     [show_id] => 11
> >                 )
>
> >             [1] => Array
> >                 (
> >                     [name] => Os
> >                     [number] => 16
> >                     [description] => While Walter attempts to figure out a way to stop the spread of vortexes on This Side, the team investigate a series of thefts committed by criminals who can control gravity.
> >                     [date] => 3/11/2011
> >                     [show_id] => 11
> >                 )
> > )
>
> > So now the saveAll() function should be working I think. Yet it still doesn't save anything to the database.
> > Should I put in a for loop and save each episode individually using the save() function? Is there any reason that would be more likely to work?
>
> Well.... saveAll() is described as being for saving one main record and multiple related records. Here, you're trying to save multiple unrelated records. I don't know if saveAll() is meant to work in that case, so maybe a for loop is the way for now after all. I hate recommending that, because I know a single multi-record SQL INSERT statement is more efficient than multiple single-record INSERTs, but I don't know how to do it in CakePHP. Then again, your previous code checked the validity of each save and counted up the number of successful saves, implying you expected some of them not to be successful; a single multi-record INSERT would either completely succeed or completely fail, so that may not be what you want anyway.

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Can't Save to DB

So I know this isn't strictly speaking CakePHP anymore and just basic php, but I'm having difficulty getting it into the correct CakePHP format, so I think it counts.
Here's the for loop I'm using to get it into the correct format (just in testing phase, it print_r's all the results):
foreach($episodes as $key => $value) {
$episode['Episode'][$key] = $value;
print_r($episode);
}
But the problem is, it gives me one array too many (the [0] array):
Array
(
[Episode] => Array
(
[0] => Array
(
[name] => The Prestidigitation Approximation
[number] => 18
[description] => Sheldon is baffled by Wolowitz&#039;s magic trick. Meanwhile, Leonard realizes dating Priya may make it impossible to continue being friends with Penny.
[date] => 3/10/2011
[show_id] => 11
)
)
)
I can't find the part in my code that adds that extra array. Any suggestions?

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Containable Query Slow - Am I doing it wrong?

TimG:

Verify that you have an index on parent_id column in categories table
(as well as a separate index on the id column). ContainableBehavior
usually tries to generate a LEFT JOIN with the belongsTo and the
hasOne related tables, so without the proper indexes, the database may
be resorting to an n x n table scan. Without any details of how you
separated the single containable query into separate queries, I would
guess that by doing so, you pretty much forced it to do only two table
scans on the categories table (once for all categories, the second for
all the unique parent categories).

On Feb 27, 11:10 pm, TimG <t...@gurske.com> wrote:
> It looks like it's just the way it is. Because of the way the
> associations are it has to query each variation. I just removed the
> variations from the containable and queried them separately and then
> combined the arrays in PHP. Much quicker now.
>
> Thanks for everybody's help!

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Probelm with hasMany relationship and find/paginate


Hi
On Sun, Feb 27, 2011 at 3:20 PM, heohni <heidi.anselstetter@consultingteam.de> wrote:
Hi,

I may have a basic missunderstanding of cakephp, but I do the
following:

I have a Member Model with some belongsTo and 1 hasMany relations.
A 'member' hasMany 'payments'.
A 'payment' belongsTo a 'member'

Now I need to create a new page where I want to show a summary of all
members with are filtered by status which I get out of the 'payments'
table.

Therefore I created a new model with no use of a database and a own
controller.
The reason for these files is, that after I show the list of members,
I have to do some other functions which I wanted to have seperate form
the members controller.

In my controller, I added
var $uses = array('Member', 'Payment');
function index(){
$this->set('results', $this->paginate());
}

This performs 3 statements:
1. count statements for the paginator functions
2. Member with all belongsTo
3. Payments

The results are OK and correct, I just need to filter out all
Payment.status != 6.
How can I do this?

I think this link will be useful

http://bakery.cakephp.org/articles/shird10/2010/08/29/pagination-for-custom-queries

$cond = array('Payment.status <>' => 1 ) ;

$this->set('results', $this->paginate('Parent', $cond));

I am not sure with which i gave . Please refrer link which I gave


I am really stuck at this point :-( and need help please!!
Regards

sathia
http://www.sathia27.wordpress.com

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Form Problem

Just in case there is any confusion my question should read as
follows:

I can't figure out how to put the buttons inside the fieldset using
CakePHP. The only solution I have so far is to set the fieldset to
false and then put <fieldset> tags around the form.
But there must be a way to do this using FormHelper.


On Feb 28, 9:50 pm, john lyles <confidentia...@gmail.com> wrote:
> I can't figure out how to put the buttons inside the fieldset using
> CakePHP. The only solution I have so far is to set the fieldset to
> false and then wrap to put the put <fieldset> tags around the form.
> But there must be a way to do this using FormHelper.
>
> <?php
> echo $this->Form->create('Contact', array('action' => 'mail', 'id' =>
> 'form', 'div' => false));
> ?>
> <fieldset><legend>Contact Form</legend>
> <?php
> echo $this->Form->inputs(array(
>         'fieldset'=>false,
>         'name' => array(
>         'label' => 'Name:',
>         'maxLength' => '25',
>         'div' => false,
>         'id' => 'name'
>     ),
>     'Contact.email' => array(
>         'label' => 'Email:',
>         'maxLength' => '50',
>         'div' => false,
>         'id' => 'email'
>     ),
>     'Contact.telephone' => array(
>         'label' => 'telephone:',
>         'maxLength' => '12',
>         'div' => false,
>         'id' => 'telephone'
>     ),
>     'Contact.reason'=>array(
>         'label' => 'Reason:',
>         'maxLength' => '25',
>         'div' => false,
>         'id' => 'reason'
>     ),
>     'Contact.message'=>array(
>         'label' => 'Message:',
>         'div' => false,
>         'id' => 'message'
>     ),
> ));
>  echo $this->Form->button('Reset', array('type' =>'reset','id' =>
> 'reset'));
>  echo $this->Form->button('Send', array('id' => 'send'));
> ?>
> </fieldset>

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: What is "=>" in an Array?



On Mon, Feb 28, 2011 at 10:17 AM, nicolas <xu.shenxin@gmail.com> wrote:
hi,

hi
in this code: $this->redirect(array('action'=>'index'));
I am absolutely new to cakePHP.  the "=>" really confuses me a lot. I
couldn't find it in PHP documentation.

It will be found in PHP .

Can anybody tell me what "=>" means exactly? and explain the syntax of
=>?

It is used to representing two dimesional array .  (assocaitive array).

Thanks a lot!


REgards,
Nicolas


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
Regards

sathia
http://www.sathia27.wordpress.com

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: A wizard did it

Cant you use the $this->Wizard->_currentStep to know where you are??

I use ajax just to load some autocomplete fields...

--
Renato de Freitas Freire
renato@morfer.org


On Tue, Mar 1, 2011 at 12:03 AM, Ryan Snowden <sicapitan@gmail.com> wrote:
I modified it to be able to use AJAX but it's got a memory problem, that is, you have to be sure which step you're in if you refresh the page :)

On 1 March 2011 08:09, Renato de Freitas Freire <renatoff@gmail.com> wrote:
One thing you have to be careful, is to save the data BEFORE redirecting to another domain.
You have a serious risk to lose your data if you dont.

The solution used by Krissy appears to be the better way to do it.

The wizard component works very well, but it had some bugs.
I had a working version with cake 1.2.8, but I didnt try to use it on 1.3 yet.
I dont know if the actual version is ready to 1.3 or it is still on 1.2, but there is a lot of tutorials to help you to use it on 1.3.

And there is some limitation too. You will have to hack the code to save checkbox fields.

--
Renato de Freitas Freire
renato@morfer.org



On Mon, Feb 28, 2011 at 7:27 PM, Krissy Masters <naked.cake.baker@gmail.com> wrote:
What I did in the same regards to cancelling payment:

User fills out form -> save username / password / set up account basics  but
I have a field User.acct_locked which I mark auto as true send them to
paypal.

If they register then cancel the payment / close window / drop computer in
the tub /  sure they can still login but all they can access is a payment
option screen since acct_locked is true (my own access function).
***********************************************************
Thank you for registering Name / Welcome back / please complete your order /
please select your subscription page:

You could even pull original order if you saved what they wanted before
cancelling.........
************************************************************

After making a payment the IPN function I added in the order what they
bought, update account subscription what not and acct_locked => false. So
once they pay they now have full access.

You could easily delete all acct_locked => 1 after 1 week / day / month
flushing out all unused / never-paid registrations. You would need to come
with a way there but should be easy enough.

K



-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Ryan Schmidt
Sent: Monday, February 28, 2011 6:32 PM
To: cake-php@googlegroups.com
Subject: A wizard did it

I'm building a multi-page signup form, using the Wizard component, which
seems to be pretty cool:

https://github.com/jaredhoyt/cakephp-wizard

After entering their preferred username, password, blood type, and mother's
maiden shoe size, I'm going to be directing users over to PayPal to pay for
these services they're signing up with me for. When the PayPal transaction
is complete, PayPal will redirect the user back to a "done" page on my site.
Or, if the transaction is cancelled in PayPal land, I believe PayPal will
redirect the user to a "cancel" page on my site. On these pages I can then
tell the user useful things, like "Thanks for giving me money" or "You
didn't give me any money".

Ultimately, I will want to use the data the customer has provided to create
several database records: users, services, etc. I'm trying to determine what
I should be doing with the user's data between the time they've entered it
and the time they've succeeded in paying me.

I could keep the data in the session only, until the "done" page is reached,
at which point I actually save() it into the appropriate models. This is how
the provided Wizard example handles it. One worry I have here is: what if
the user picked a username, and I validated on page 1 of the wizard that it
was unique, but by the time they came back from PayPal, someone else created
that username. So the user paid me, but the save() into the database with
all the data about what they paid me for fails. Maybe this is a rare enough
occasion that I can get away with just logging all the data and manually
fixing this later.

I could create the e.g. User and Service records as soon as I have enough
data from the customer. What if the user cancels the PayPal transaction? In
the "cancel" page, I could delete the records again. What if the user just
closes the window when they see the PayPal screen? My "cancel" page will
never be reached and I'll have stale records lingering in the database. What
if the user later comes back and tries again? Now the username they wanted
to pick is already sitting around unused in my database and they can't have
it anymore.

To avoid stale or unfinished records in important tables like users and
services, I could have an entirely new table, orders, and fill it with
information about the order. After coming back from PayPal successfully, I
could mark the order as ready to be filled. Then I'd need to transfer the
data from the orders table into corresponding users and services records.

Does anyone here have experience doing this kind of signup form and could
share some recommendations? I'd love to hear what you did and whether it
worked well.






--
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+unsubscribe@googlegroups.com For more options, visit this group at
http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Multiple "controllers" on a single page

Just wondering what the Cake PHP approach would be if one were
creating a single page that presented: a user list, recent posting
list and recent file upload list. Right now I have separate
controllers for each so I can view each item on its own page. How
would I use Cake PHP to present all of this data on one page? Would
one make a master controller that makes use of the other three or
break the controllers into components? And how could / can the views
for each item be re-used in such a situation?

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: A wizard did it

I modified it to be able to use AJAX but it's got a memory problem, that is, you have to be sure which step you're in if you refresh the page :)

On 1 March 2011 08:09, Renato de Freitas Freire <renatoff@gmail.com> wrote:
One thing you have to be careful, is to save the data BEFORE redirecting to another domain.
You have a serious risk to lose your data if you dont.

The solution used by Krissy appears to be the better way to do it.

The wizard component works very well, but it had some bugs.
I had a working version with cake 1.2.8, but I didnt try to use it on 1.3 yet.
I dont know if the actual version is ready to 1.3 or it is still on 1.2, but there is a lot of tutorials to help you to use it on 1.3.

And there is some limitation too. You will have to hack the code to save checkbox fields.

--
Renato de Freitas Freire
renato@morfer.org



On Mon, Feb 28, 2011 at 7:27 PM, Krissy Masters <naked.cake.baker@gmail.com> wrote:
What I did in the same regards to cancelling payment:

User fills out form -> save username / password / set up account basics  but
I have a field User.acct_locked which I mark auto as true send them to
paypal.

If they register then cancel the payment / close window / drop computer in
the tub /  sure they can still login but all they can access is a payment
option screen since acct_locked is true (my own access function).
***********************************************************
Thank you for registering Name / Welcome back / please complete your order /
please select your subscription page:

You could even pull original order if you saved what they wanted before
cancelling.........
************************************************************

After making a payment the IPN function I added in the order what they
bought, update account subscription what not and acct_locked => false. So
once they pay they now have full access.

You could easily delete all acct_locked => 1 after 1 week / day / month
flushing out all unused / never-paid registrations. You would need to come
with a way there but should be easy enough.

K



-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Ryan Schmidt
Sent: Monday, February 28, 2011 6:32 PM
To: cake-php@googlegroups.com
Subject: A wizard did it

I'm building a multi-page signup form, using the Wizard component, which
seems to be pretty cool:

https://github.com/jaredhoyt/cakephp-wizard

After entering their preferred username, password, blood type, and mother's
maiden shoe size, I'm going to be directing users over to PayPal to pay for
these services they're signing up with me for. When the PayPal transaction
is complete, PayPal will redirect the user back to a "done" page on my site.
Or, if the transaction is cancelled in PayPal land, I believe PayPal will
redirect the user to a "cancel" page on my site. On these pages I can then
tell the user useful things, like "Thanks for giving me money" or "You
didn't give me any money".

Ultimately, I will want to use the data the customer has provided to create
several database records: users, services, etc. I'm trying to determine what
I should be doing with the user's data between the time they've entered it
and the time they've succeeded in paying me.

I could keep the data in the session only, until the "done" page is reached,
at which point I actually save() it into the appropriate models. This is how
the provided Wizard example handles it. One worry I have here is: what if
the user picked a username, and I validated on page 1 of the wizard that it
was unique, but by the time they came back from PayPal, someone else created
that username. So the user paid me, but the save() into the database with
all the data about what they paid me for fails. Maybe this is a rare enough
occasion that I can get away with just logging all the data and manually
fixing this later.

I could create the e.g. User and Service records as soon as I have enough
data from the customer. What if the user cancels the PayPal transaction? In
the "cancel" page, I could delete the records again. What if the user just
closes the window when they see the PayPal screen? My "cancel" page will
never be reached and I'll have stale records lingering in the database. What
if the user later comes back and tries again? Now the username they wanted
to pick is already sitting around unused in my database and they can't have
it anymore.

To avoid stale or unfinished records in important tables like users and
services, I could have an entirely new table, orders, and fill it with
information about the order. After coming back from PayPal successfully, I
could mark the order as ready to be filled. Then I'd need to transfer the
data from the orders table into corresponding users and services records.

Does anyone here have experience doing this kind of signup form and could
share some recommendations? I'd love to hear what you did and whether it
worked well.






--
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+unsubscribe@googlegroups.com For more options, visit this group at
http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Form Problem

I can't figure out how to put the buttons inside the fieldset using
CakePHP. The only solution I have so far is to set the fieldset to
false and then wrap to put the put <fieldset> tags around the form.
But there must be a way to do this using FormHelper.


<?php
echo $this->Form->create('Contact', array('action' => 'mail', 'id' =>
'form', 'div' => false));
?>
<fieldset><legend>Contact Form</legend>
<?php
echo $this->Form->inputs(array(
'fieldset'=>false,
'name' => array(
'label' => 'Name:',
'maxLength' => '25',
'div' => false,
'id' => 'name'
),
'Contact.email' => array(
'label' => 'Email:',
'maxLength' => '50',
'div' => false,
'id' => 'email'
),
'Contact.telephone' => array(
'label' => 'telephone:',
'maxLength' => '12',
'div' => false,
'id' => 'telephone'
),
'Contact.reason'=>array(
'label' => 'Reason:',
'maxLength' => '25',
'div' => false,
'id' => 'reason'
),
'Contact.message'=>array(
'label' => 'Message:',
'div' => false,
'id' => 'message'
),
));
echo $this->Form->button('Reset', array('type' =>'reset','id' =>
'reset'));
echo $this->Form->button('Send', array('id' => 'send'));
?>
</fieldset>

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: EmailComponent improvements

To further stir the discussion, here are some of the existing issues
open for EmailComponent:

- http://cakephp.lighthouseapp.com/projects/42648/tickets/1336-rfc-change-the-email-system
- http://cakephp.lighthouseapp.com/projects/42648/tickets/1414-config-for-email-component
- http://cakephp.lighthouseapp.com/projects/42648/tickets/14-email-component-should-set-mime-version-header-when-sendas-html-or-both
- http://cakephp.lighthouseapp.com/projects/42648/tickets/1247-centralized-location-for-smtp-configuration

Does anyone have any strong feelings about these, or other problems
they've had with EmailComponent?

-Mark

On Feb 27, 12:29 pm, Juan Basso <jrba...@gmail.com> wrote:
> Hey guys,
>
> The core team is working in changes to improve the form to send e-
> mails for cake 2.0. With these changes will be possible send e-mail
> from others layers of the application, like in shells.
>
> I would like your help to say what is the good and bad points from the
> actual solution. What is missing? What we need to improve?
>
> Any help will be welcome.
>
> Thanks,
>
> Core Team

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Join Table being wiped.

Hi Guys,

I've got a HABTM relationship between subcategories and resources.
There is a resources_subcategories join table. I've written a method
on subcategories that changes the order field in a record by
decrementing it. It's a bit like the tree behaviour (which I may
resort to if I cannot get this to work).

function up($id = null, $order = null) {
if (!$id or !$order) {
$this->Session->setFlash(__('Invalid id or order number', true));
$this->redirect(array('action'=>'index'));
}
// Create an array of the image table contents of IDs and Orders.
$conditions = array(
'fields' => array('id','order'),
'order' => 'Subcategory.order ASC'
);
$subcategories = $this->Subcategory->find('all', $conditions);
// Set the direction for the image to travel (up)
$delta = -1;
// index = the array item you want to move
// delta = the direction and number of spaces to move the item.
$index = $order -1;
$index2 = $index + $delta;
// Move the elements in the array
$temp_item = $subcategories[$index2]['Subcategory']['order'];
$subcategories[$index2]['Subcategory']['order'] =
$subcategories[$index]['Subcategory']['order'];
$subcategories[$index]['Subcategory']['order'] = $temp_item;
// Write it all back to the database
foreach ($subcategories as $subcategory):
$this->Subcategory->save($subcategory, false, array('id',
'order'));
endforeach;
$this->redirect(array('action' => 'index'));
}

This all works perfectly except for one thing. Each time this method
is run the entire contents of the join table is erased. I need an
idiot check. Can anyone see what it is I am doing wrong? Thanks in
advance for any help anyone can offer.

Adam.

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Miles Johnson Uploader - Resize Group Issue.

Yeah that's quite weird, it should be assigned as an image.

What does php say the mimetype is after the upload process?

On Feb 28, 4:17 pm, Stephen <step...@ninjacodermonkey.co.uk> wrote:
> Hi Miles
>
> I tried image/jpeg and gif.
>
> Various images, not had the chance to test online rather than in EasyPHP.
>
> image/jpeg should pass no?
>
> Anyhow, on a slightly different note, I really love the simplicity of your
> component - besides the strange error (still convinced it's EasyPHP), it's
> working perfectly.
>
> On 28 February 2011 22:19, Miles J <mileswjohn...@gmail.com> wrote:
>
>
>
> > What type of file are you uploading?
>
> > You can add more mimetypes to the supported mimetype array to allow
> > your type to pass, instead of hacking in conditions.
>
> > On Feb 28, 12:17 pm, Stephen <step...@ninjacodermonkey.co.uk> wrote:
> > > I managed to get around this issue by checking for both image and
> > > application from an array (at all instances).
>
> > > This obviously is bad practise, I am sure this will be because of
> > EasyPHP,
> > > possibly something to do with the way CakePHP handles tmp_name?
>
> > > If anybody has any insight on this I would love to hear.
>
> > > Thanks in advanced -
> > > <http://www.ninjacodermonkey.co.uk>
> > >  Stephen
>
> > --
> > Our newest site for the community: CakePHP Video Tutorials
> >http://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group
> > athttp://groups.google.com/group/cake-php
>
> --
> Kind Regards
>  Stephen
>
>  http://www.ninjacodermonkey.co.uk

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Miles Johnson Uploader - Resize Group Issue.

Hi Miles

I tried image/jpeg and gif.

Various images, not had the chance to test online rather than in EasyPHP.

image/jpeg should pass no?

Anyhow, on a slightly different note, I really love the simplicity of your component - besides the strange error (still convinced it's EasyPHP), it's working perfectly.

On 28 February 2011 22:19, Miles J <mileswjohnson@gmail.com> wrote:
What type of file are you uploading?

You can add more mimetypes to the supported mimetype array to allow
your type to pass, instead of hacking in conditions.

On Feb 28, 12:17 pm, Stephen <step...@ninjacodermonkey.co.uk> wrote:
> I managed to get around this issue by checking for both image and
> application from an array (at all instances).
>
> This obviously is bad practise, I am sure this will be because of EasyPHP,
> possibly something to do with the way CakePHP handles tmp_name?
>
> If anybody has any insight on this I would love to hear.
>
> Thanks in advanced -
>  Stephen

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
Kind Regards
 Stephen

 http://www.ninjacodermonkey.co.uk


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: A wizard did it

One thing you have to be careful, is to save the data BEFORE redirecting to another domain.
You have a serious risk to lose your data if you dont.

The solution used by Krissy appears to be the better way to do it.

The wizard component works very well, but it had some bugs.
I had a working version with cake 1.2.8, but I didnt try to use it on 1.3 yet.
I dont know if the actual version is ready to 1.3 or it is still on 1.2, but there is a lot of tutorials to help you to use it on 1.3.

And there is some limitation too. You will have to hack the code to save checkbox fields.

--
Renato de Freitas Freire
renato@morfer.org


On Mon, Feb 28, 2011 at 7:27 PM, Krissy Masters <naked.cake.baker@gmail.com> wrote:
What I did in the same regards to cancelling payment:

User fills out form -> save username / password / set up account basics  but
I have a field User.acct_locked which I mark auto as true send them to
paypal.

If they register then cancel the payment / close window / drop computer in
the tub /  sure they can still login but all they can access is a payment
option screen since acct_locked is true (my own access function).
***********************************************************
Thank you for registering Name / Welcome back / please complete your order /
please select your subscription page:

You could even pull original order if you saved what they wanted before
cancelling.........
************************************************************

After making a payment the IPN function I added in the order what they
bought, update account subscription what not and acct_locked => false. So
once they pay they now have full access.

You could easily delete all acct_locked => 1 after 1 week / day / month
flushing out all unused / never-paid registrations. You would need to come
with a way there but should be easy enough.

K



-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Ryan Schmidt
Sent: Monday, February 28, 2011 6:32 PM
To: cake-php@googlegroups.com
Subject: A wizard did it

I'm building a multi-page signup form, using the Wizard component, which
seems to be pretty cool:

https://github.com/jaredhoyt/cakephp-wizard

After entering their preferred username, password, blood type, and mother's
maiden shoe size, I'm going to be directing users over to PayPal to pay for
these services they're signing up with me for. When the PayPal transaction
is complete, PayPal will redirect the user back to a "done" page on my site.
Or, if the transaction is cancelled in PayPal land, I believe PayPal will
redirect the user to a "cancel" page on my site. On these pages I can then
tell the user useful things, like "Thanks for giving me money" or "You
didn't give me any money".

Ultimately, I will want to use the data the customer has provided to create
several database records: users, services, etc. I'm trying to determine what
I should be doing with the user's data between the time they've entered it
and the time they've succeeded in paying me.

I could keep the data in the session only, until the "done" page is reached,
at which point I actually save() it into the appropriate models. This is how
the provided Wizard example handles it. One worry I have here is: what if
the user picked a username, and I validated on page 1 of the wizard that it
was unique, but by the time they came back from PayPal, someone else created
that username. So the user paid me, but the save() into the database with
all the data about what they paid me for fails. Maybe this is a rare enough
occasion that I can get away with just logging all the data and manually
fixing this later.

I could create the e.g. User and Service records as soon as I have enough
data from the customer. What if the user cancels the PayPal transaction? In
the "cancel" page, I could delete the records again. What if the user just
closes the window when they see the PayPal screen? My "cancel" page will
never be reached and I'll have stale records lingering in the database. What
if the user later comes back and tries again? Now the username they wanted
to pick is already sitting around unused in my database and they can't have
it anymore.

To avoid stale or unfinished records in important tables like users and
services, I could have an entirely new table, orders, and fill it with
information about the order. After coming back from PayPal successfully, I
could mark the order as ready to be filled. Then I'd need to transfer the
data from the orders table into corresponding users and services records.

Does anyone here have experience doing this kind of signup form and could
share some recommendations? I'd love to hear what you did and whether it
worked well.






--
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+unsubscribe@googlegroups.com For more options, visit this group at
http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Pagination: URL for last page

Jeremy,
I was searching a while for this simple last() solution. I recall reading about the first and last methods, but imagine my trouble searching keywords 'first' and 'last' in Google and Cake doc!!. Thanks for refreshing memory. This is how I ran it:

<?php echo $this->Paginator->first(__('[ << first page ]', true), array(), null, array('class' => 'disabled')); ?>
.....
<?php echo $this->Paginator->last(__('[ last page >> ]', true), array(), null, array('class' => 'disabled')); ?>

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

RE: A wizard did it

What I did in the same regards to cancelling payment:

User fills out form -> save username / password / set up account basics but
I have a field User.acct_locked which I mark auto as true send them to
paypal.

If they register then cancel the payment / close window / drop computer in
the tub / sure they can still login but all they can access is a payment
option screen since acct_locked is true (my own access function).
***********************************************************
Thank you for registering Name / Welcome back / please complete your order /
please select your subscription page:

You could even pull original order if you saved what they wanted before
cancelling.........
************************************************************

After making a payment the IPN function I added in the order what they
bought, update account subscription what not and acct_locked => false. So
once they pay they now have full access.

You could easily delete all acct_locked => 1 after 1 week / day / month
flushing out all unused / never-paid registrations. You would need to come
with a way there but should be easy enough.

K

-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Ryan Schmidt
Sent: Monday, February 28, 2011 6:32 PM
To: cake-php@googlegroups.com
Subject: A wizard did it

I'm building a multi-page signup form, using the Wizard component, which
seems to be pretty cool:

https://github.com/jaredhoyt/cakephp-wizard

After entering their preferred username, password, blood type, and mother's
maiden shoe size, I'm going to be directing users over to PayPal to pay for
these services they're signing up with me for. When the PayPal transaction
is complete, PayPal will redirect the user back to a "done" page on my site.
Or, if the transaction is cancelled in PayPal land, I believe PayPal will
redirect the user to a "cancel" page on my site. On these pages I can then
tell the user useful things, like "Thanks for giving me money" or "You
didn't give me any money".

Ultimately, I will want to use the data the customer has provided to create
several database records: users, services, etc. I'm trying to determine what
I should be doing with the user's data between the time they've entered it
and the time they've succeeded in paying me.

I could keep the data in the session only, until the "done" page is reached,
at which point I actually save() it into the appropriate models. This is how
the provided Wizard example handles it. One worry I have here is: what if
the user picked a username, and I validated on page 1 of the wizard that it
was unique, but by the time they came back from PayPal, someone else created
that username. So the user paid me, but the save() into the database with
all the data about what they paid me for fails. Maybe this is a rare enough
occasion that I can get away with just logging all the data and manually
fixing this later.

I could create the e.g. User and Service records as soon as I have enough
data from the customer. What if the user cancels the PayPal transaction? In
the "cancel" page, I could delete the records again. What if the user just
closes the window when they see the PayPal screen? My "cancel" page will
never be reached and I'll have stale records lingering in the database. What
if the user later comes back and tries again? Now the username they wanted
to pick is already sitting around unused in my database and they can't have
it anymore.

To avoid stale or unfinished records in important tables like users and
services, I could have an entirely new table, orders, and fill it with
information about the order. After coming back from PayPal successfully, I
could mark the order as ready to be filled. Then I'd need to transfer the
data from the orders table into corresponding users and services records.

Does anyone here have experience doing this kind of signup form and could
share some recommendations? I'd love to hear what you did and whether it
worked well.


--
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+unsubscribe@googlegroups.com For more options, visit this group at
http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Miles Johnson Uploader - Resize Group Issue.

What type of file are you uploading?

You can add more mimetypes to the supported mimetype array to allow
your type to pass, instead of hacking in conditions.

On Feb 28, 12:17 pm, Stephen <step...@ninjacodermonkey.co.uk> wrote:
> I managed to get around this issue by checking for both image and
> application from an array (at all instances).
>
> This obviously is bad practise, I am sure this will be because of EasyPHP,
> possibly something to do with the way CakePHP handles tmp_name?
>
> If anybody has any insight on this I would love to hear.
>
> Thanks in advanced -
> <http://www.ninjacodermonkey.co.uk>
>  Stephen

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

A wizard did it

I'm building a multi-page signup form, using the Wizard component, which seems to be pretty cool:

https://github.com/jaredhoyt/cakephp-wizard

After entering their preferred username, password, blood type, and mother's maiden shoe size, I'm going to be directing users over to PayPal to pay for these services they're signing up with me for. When the PayPal transaction is complete, PayPal will redirect the user back to a "done" page on my site. Or, if the transaction is cancelled in PayPal land, I believe PayPal will redirect the user to a "cancel" page on my site. On these pages I can then tell the user useful things, like "Thanks for giving me money" or "You didn't give me any money".

Ultimately, I will want to use the data the customer has provided to create several database records: users, services, etc. I'm trying to determine what I should be doing with the user's data between the time they've entered it and the time they've succeeded in paying me.

I could keep the data in the session only, until the "done" page is reached, at which point I actually save() it into the appropriate models. This is how the provided Wizard example handles it. One worry I have here is: what if the user picked a username, and I validated on page 1 of the wizard that it was unique, but by the time they came back from PayPal, someone else created that username. So the user paid me, but the save() into the database with all the data about what they paid me for fails. Maybe this is a rare enough occasion that I can get away with just logging all the data and manually fixing this later.

I could create the e.g. User and Service records as soon as I have enough data from the customer. What if the user cancels the PayPal transaction? In the "cancel" page, I could delete the records again. What if the user just closes the window when they see the PayPal screen? My "cancel" page will never be reached and I'll have stale records lingering in the database. What if the user later comes back and tries again? Now the username they wanted to pick is already sitting around unused in my database and they can't have it anymore.

To avoid stale or unfinished records in important tables like users and services, I could have an entirely new table, orders, and fill it with information about the order. After coming back from PayPal successfully, I could mark the order as ready to be filled. Then I'd need to transfer the data from the orders table into corresponding users and services records.

Does anyone here have experience doing this kind of signup form and could share some recommendations? I'd love to hear what you did and whether it worked well.


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Can't Save to DB

On Feb 28, 2011, at 15:22, cricket wrote:

> $this->Episode->create();
> $this->Episode->set($episode);

Is that in the book? I'm having trouble finding it... searching for "create" gives me no method by that name, and searching for "set" gets me the "set" in the View class.

How is ...->create() and ...->set($episode) different from ...->save($episode)?


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Can't Save to DB

On Sun, Feb 27, 2011 at 10:01 AM, theweirdone <theweirdone@gmail.com> wrote:
> Hi,
> I'm new to CakePHP, and I'm working on a personal project.
> I've run into a small problem, which is I can't save certain things to
> the database. I've tried a few different sources for help (3 seperate
> forums) with no success. So I'm trying here now. The only problem is
> there's no formating in this, so I'll just supply the link to the
> forum post.
>
> http://www.daniweb.com/forums/thread349932.html

$this->Episode->create();
$this->Episode->set($episode);

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: how to redirect and let the server do some lengthy job in the background?

On Feb 28, 2011, at 14:46, Tan Cheng wrote:

> Thank you!!! Also, I understand that you did not mean to encode the
> video in the $LOCK folder. I didn't express myself clearly, seems like
> I need help not only with programming language...
>
> Thanks again for spending almost the whole day inspiring me. Makes me
> just love cakephp even more!

Then my work here is done (for now). Good luck with your code!


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Can't Save to DB

On Feb 28, 2011, at 14:23, theweirdone wrote:

> I've changed my code, here's the new controller:
>
> function addAll($id = null) {
> if (!$id) {
> $this->Session->setFlash(__('Invalid show id entered', true));
> //$this->redirect('/episodes');
> }
> $show = $this->requestAction('/shows/getTvById/'.$id); //gets the tv.com url
> $episodes = $this->scrape($show, $id); //scrapes tv.com for the show
> $this->set('episodes', $episodes); //sets $TVshowInfo for the view
> if($this->Episode->saveAll($episodes['Episode'])){
> $this->Session->setFlash(__($count.' episodes were saved.', true));
> }
> }
>
> I've also updated the scraper to return the array such as in the manual:
>
> Array
> (
> [Episode] => Array
> (
> [0] => Array
> (
> [name] => Stowaway
> [number] => 17
> [description] => No synopsis available. Write a synopsis.
> [date] => 3/18/2011
> [show_id] => 11
> )
>
> [1] => Array
> (
> [name] => Os
> [number] => 16
> [description] => While Walter attempts to figure out a way to stop the spread of vortexes on This Side, the team investigate a series of thefts committed by criminals who can control gravity.
> [date] => 3/11/2011
> [show_id] => 11
> )
> )
>
> So now the saveAll() function should be working I think. Yet it still doesn't save anything to the database.
> Should I put in a for loop and save each episode individually using the save() function? Is there any reason that would be more likely to work?

Well.... saveAll() is described as being for saving one main record and multiple related records. Here, you're trying to save multiple unrelated records. I don't know if saveAll() is meant to work in that case, so maybe a for loop is the way for now after all. I hate recommending that, because I know a single multi-record SQL INSERT statement is more efficient than multiple single-record INSERTs, but I don't know how to do it in CakePHP. Then again, your previous code checked the validity of each save and counted up the number of successful saves, implying you expected some of them not to be successful; a single multi-record INSERT would either completely succeed or completely fail, so that may not be what you want anyway.

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: how to redirect and let the server do some lengthy job in the background?

Thank you!!! Also, I understand that you did not mean to encode the
video in the $LOCK folder. I didn't express myself clearly, seems like
I need help not only with programming language...

Thanks again for spending almost the whole day inspiring me. Makes me
just love cakephp even more!

-David

On Feb 28, 3:38 pm, Ryan Schmidt <google-2...@ryandesign.com> wrote:
> On Feb 28, 2011, at 14:29, Tan Cheng wrote:
>
> > Also, I want to ask if I create the shell as cakephp shell, will that
> > shell be restricted by the "max_execution_time" in php.ini?
>
> According to the comments here...
>
> http://php.net/set-time-limit
>
> ...the time limit defaults to unlimited on the command line PHP SAPI.

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: how to redirect and let the server do some lengthy job in the background?

On Feb 28, 2011, at 14:29, Tan Cheng wrote:

> Also, I want to ask if I create the shell as cakephp shell, will that
> shell be restricted by the "max_execution_time" in php.ini?


According to the comments here...

http://php.net/set-time-limit

...the time limit defaults to unlimited on the command line PHP SAPI.


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: how to redirect and let the server do some lengthy job in the background?

I see, this is really complicated, so I think I'll try from mkdir.
Also, I want to ask if I create the shell as cakephp shell, will that
shell be restricted by the "max_execution_time" in php.ini?

Thanks,

-David

On Feb 28, 3:22 pm, Ryan Schmidt <google-2...@ryandesign.com> wrote:
> On Feb 28, 2011, at 13:55, Tan Cheng wrote:
>
> > This is a great idea! So whichever script starts encoding, it takes
> > place in the $LOCKS folder, then everytime before a new script starts
> > running it will always check if the "$LOCK room" is empty, and runs
> > only if it's empty. Brilliant! See how far I can go with all the
> > ideas...
>
> I hadn't meant for encoding to occur in the locks directory; I had only meant for the locks directory to contain locks -- empty files with carefully-chosen names that signify when an instance of the encoder daemon is running. The encoding itself (i.e. the creation by ffmpeg of temporary files related to encoding a particular video) should occur in a different directory; $APP/tmp/encoder maybe.
>
> Also, just checking if the directory is empty before starting isn't enough; that allows a race condition. Consider: two instances of the encoder daemon are started simultaneously for some reason and run more or less in parallel, because the OS is multithreaded. Both instances check the directory and find it to be empty. Both scripts then decide they should continue, both scripts create their locks, and both scripts begin encoding the same videos. My suggestion of first creating the lock, then checking if there are any other locks, should guarantee that you will never have two encoder daemons running at once, which is the situation that must be prevented. There's still a race condition leading to the possibility that both instances will decide to quit without doing any work, but that's ok; it'll run again in a short interval anyway, via cron.
>
> Just be sure your script doesn't have a bug in it that causes it to exit prematurely and not clean up the lock file.
>
> Another idea, instead of lock files, would be to simply create a specific directory when beginning to encode. PHP's mkdir returns false (and triggers a warning) if the directory already exists -- if so, it's because another encoder daemon is running so you just exit.
>
> <?php
>
> $encoder_tmp_dir = "$APP/tmp/encoder";
> if (@mkdir($encoder_tmp_dir)) {
>         $videos = array();
>         do {
>                 $videos = getUnencodedVideos();
>                 foreach ($videos as $video) {
>                         encodeVideo($video);
>                 }
>         } while (!empty($videos));
>         rmdir($encoder_tmp_dir);
>
> }
>
> ?>
>
> (This assumes PHP's mkdir() function doesn't itself have a race condition.)
>
> Race conditions are challenging to handle correctly, and I'm sure somebody else can suggest a better way to do this, but that's what I came up with for now.
>
> By the way, even if you decide to go for an always-running single-instance daemon as originally discussed, this lock stuff is good to implement anyway. If your daemon relies on the fact that there's only one copy of itself running, it's a good idea to write the code so that if more than one instance is inadvertently started, it won't break things.

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Can't Save to DB

Hey
Thanks already for all the help.
I've changed my code, here's the new controller:

function addAll($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid show id entered', true));
            //$this->redirect('/episodes');
        }
        $show = $this->requestAction('/shows/getTvById/'.$id); //gets the tv.com url
        $episodes = $this->scrape($show, $id); //scrapes tv.com for the show
        $this->set('episodes', $episodes); //sets $TVshowInfo for the view
        if($this->Episode->saveAll($episodes['Episode'])){
            $this->Session->setFlash(__($count.' episodes were saved.', true));
        }
    }

I've also updated the scraper to return the array such as in the manual:

Array
(
    [Episode] => Array
        (
            [0] => Array
                (
                    [name] => Stowaway
                    [number] => 17
                    [description] => No synopsis available. Write a synopsis.
                    [date] => 3/18/2011
                    [show_id] => 11
                )

            [1] => Array
                (
                    [name] => Os
                    [number] => 16
                    [description] => While Walter attempts to figure out a way to stop the spread of vortexes on This Side, the team investigate a series of thefts committed by criminals who can control gravity.
                    [date] => 3/11/2011
                    [show_id] => 11
                )
)

So now the saveAll() function should be working I think. Yet it still doesn't save anything to the database.
Should I put in a for loop and save each episode individually using the save() function? Is there any reason that would be more likely to work?

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: how to redirect and let the server do some lengthy job in the background?

On Feb 28, 2011, at 13:55, Tan Cheng wrote:

> This is a great idea! So whichever script starts encoding, it takes
> place in the $LOCKS folder, then everytime before a new script starts
> running it will always check if the "$LOCK room" is empty, and runs
> only if it's empty. Brilliant! See how far I can go with all the
> ideas...


I hadn't meant for encoding to occur in the locks directory; I had only meant for the locks directory to contain locks -- empty files with carefully-chosen names that signify when an instance of the encoder daemon is running. The encoding itself (i.e. the creation by ffmpeg of temporary files related to encoding a particular video) should occur in a different directory; $APP/tmp/encoder maybe.

Also, just checking if the directory is empty before starting isn't enough; that allows a race condition. Consider: two instances of the encoder daemon are started simultaneously for some reason and run more or less in parallel, because the OS is multithreaded. Both instances check the directory and find it to be empty. Both scripts then decide they should continue, both scripts create their locks, and both scripts begin encoding the same videos. My suggestion of first creating the lock, then checking if there are any other locks, should guarantee that you will never have two encoder daemons running at once, which is the situation that must be prevented. There's still a race condition leading to the possibility that both instances will decide to quit without doing any work, but that's ok; it'll run again in a short interval anyway, via cron.

Just be sure your script doesn't have a bug in it that causes it to exit prematurely and not clean up the lock file.

Another idea, instead of lock files, would be to simply create a specific directory when beginning to encode. PHP's mkdir returns false (and triggers a warning) if the directory already exists -- if so, it's because another encoder daemon is running so you just exit.

<?php

$encoder_tmp_dir = "$APP/tmp/encoder";
if (@mkdir($encoder_tmp_dir)) {
$videos = array();
do {
$videos = getUnencodedVideos();
foreach ($videos as $video) {
encodeVideo($video);
}
} while (!empty($videos));
rmdir($encoder_tmp_dir);
}

?>

(This assumes PHP's mkdir() function doesn't itself have a race condition.)

Race conditions are challenging to handle correctly, and I'm sure somebody else can suggest a better way to do this, but that's what I came up with for now.


By the way, even if you decide to go for an always-running single-instance daemon as originally discussed, this lock stuff is good to implement anyway. If your daemon relies on the fact that there's only one copy of itself running, it's a good idea to write the code so that if more than one instance is inadvertently started, it won't break things.


--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: Miles Johnson Uploader - Resize Group Issue.

I managed to get around this issue by checking for both image and application from an array (at all instances).

This obviously is bad practise, I am sure this will be because of EasyPHP, possibly something to do with the way CakePHP handles tmp_name?

If anybody has any insight on this I would love to hear.

Thanks in advanced -

 Stephen

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Re: how to redirect and let the server do some lengthy job in the background?

This is a great idea! So whichever script starts encoding, it takes
place in the $LOCKS folder, then everytime before a new script starts
running it will always check if the "$LOCK room" is empty, and runs
only if it's empty. Brilliant! See how far I can go with all the
ideas...

THANK YOU, Ryan!!

On Feb 28, 2:21 pm, Ryan Schmidt <google-2...@ryandesign.com> wrote:
> On Feb 28, 2011, at 12:42, Tan Cheng wrote:
>
> > Thanks for all the input!!! So much good information to learn. Due to
> > the tight budget and maybe the site traffic will not be so high, I am
> > still looking at a shard hosting which supports cron, and maybe let it
> > run a cake shell every 5 hours to encode and update the database. I
> > think I am going to do some testing on my ubuntu localhost first. My
> > goal here may to get my feet wet before thinking about vps with a
> > queue system.
>
> The advantage of having a single daemon that just keeps on running is that you don't have to worry that there's another copy of the daemon running at the same time, possibly competing for encoding the same video. If you run the script via cron on an interval, it is possible that the script will take longer than that interval to run, which would introduce this problem. So if you're going to do this, then you have to handle it, for example by ensuring only one copy of the script can encode videos at a time. A lock file would be one simple idea that could work. (Designate a directory to contain locks, let's say "$APP/encoder/locks" (hereafter "$LOCKS"). When the daemon starts, create (touch) an empty file "$LOCKS/$UNIQUE" where $UNIQUE is something unique to this encoder instance, for example its process id or better yet a generated a UUID. Then check if there are any files in $LOCKS other than $UNIQUE. If there are, that means there are other encoders running; delete the lock and exit and do no encoding. Otherwise, proceed with encoding videos as discussed before, except instead of looping forever, loop until there are no more videos to encode, then delete the lock and exit.) With this in place, you could schedule the script to run as often as you like (every hour, every half hour, every 5 minutes) to guarantee users' videos are encoded as quickly as you need, without risk of the script competing with another instance of itself.

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php