Re: Save Uploaded/Parsed File to Database Table

2013-02-05 Thread Karl Smith
I solved my problem. I added the following to my controller

$this->data['Spreadsheet']['coverage_id'] = $this->Coverage->id;
$this->data['Spreadsheet']['user_id'] = $this->Auth->user('id');
$this->data['Spreadsheet']['filename'] = $uploadedFile['name'];
$this->data['Spreadsheet']['filepath'] = 
'x//xx/xxx/xx';
$this->Coverage->Spreadsheet->save($this->data);
$this->set(compact('coverage_id'));


and I added this to my view



UiForm->input('coverage_id', array('type' => 'hidden')); ?>


Hope this helps someone!


-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Save Uploaded/Parsed File to Database Table

2013-01-24 Thread lowpass
On Thu, Jan 24, 2013 at 1:45 PM, Karl Smith  wrote:
> And I am suppose to set the Model ID in the controller right?

Yes. See here:

http://cakephp.org/pages/documentation

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-24 Thread Karl Smith
And I am suppose to set the Model ID in the controller right?

On Wednesday, January 23, 2013 12:56:15 PM UTC-6, cricket wrote:
>
> On Wed, Jan 23, 2013 at 11:41 AM, Karl Smith 
> > 
> wrote: 
> > I just want to verify that my logic is right before I move 
> forward...If 
> > I use UiForm->input('id', array('type' => 'hidden')); 
>  to 
> > pass my id to my controllerthe id will be automagically added to my 
> > $data array...correct? 
>
> Not exactly. FormHelper populates inputs based on what's in 
> $this->request->data. But since you're not trying to populate an 
> entire form so as to edit the record, you can just do this: 
>
> $this->set('model_id', $model_id); 
>
> view: 
>
> echo $form->hidden('Model.id', array('value' => $model_id)); 
>

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-23 Thread lowpass
On Wed, Jan 23, 2013 at 11:41 AM, Karl Smith  wrote:
> I just want to verify that my logic is right before I move forward...If
> I use UiForm->input('id', array('type' => 'hidden'));  to
> pass my id to my controllerthe id will be automagically added to my
> $data array...correct?

Not exactly. FormHelper populates inputs based on what's in
$this->request->data. But since you're not trying to populate an
entire form so as to edit the record, you can just do this:

$this->set('model_id', $model_id);

view:

echo $form->hidden('Model.id', array('value' => $model_id));

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-23 Thread Karl Smith
I just want to verify that my logic is right before I move forward...If 
I use UiForm->input('id', array('type' => 'hidden'));  to 
pass my id to my controllerthe id will be automagically added to my 
$data array...correct? 

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-18 Thread Karl Smith
Yea I know.Im somewhat new to this.

On Fri, Jan 18, 2013 at 1:01 PM, lowpass  wrote:

> Technically, yes. But without knowing the details of what you're
> doing, take that with a grain of salt.
>
> You might want to specify the model, for one thing.
>
> On Fri, Jan 18, 2013 at 10:02 AM, Karl Smith  wrote:
> > Is it possible to pass the id to my action like this?
> >
> > UiForm->input('id', array('type' => 'hidden')); ?>
> >
> >
> >
> >
> > On Thu, Jan 17, 2013 at 5:56 PM, lowpass  wrote:
> >>
> >> On Wed, Jan 16, 2013 at 5:37 PM, Karl Smith 
> wrote:
> >> >
> >> >
> >> >>
> >> >> > Now as far as my view goes..do I need to add an input for user_id
> and
> >> >> > coverage_id as hidden fields?
> >> >>
> >> >> The user_id you can add manually after the upload with
> >> >> $this->Auth->user('id') but for coverage_id you can either use a
> >> >> hidden form field or add that data to the array before saving as
> well.
> >> >> Either way, you'll need to know what the coverage_id is so you should
> >> >> pass it to the action in the first place:
> >> >>
> >> >> echo $this->Html->link(
> >> >> 'upload spreadsheet',
> >> >> array(
> >> >> 'controller' => 'Coverages',
> >> >> 'action' => 'processSpreadsheet',
> >> >> 'coverage_id' => $xxx
> >> >> )
> >> >> );
> >> >>
> >> > Ok...I have a quick questionis there another way to pass the
> >> > coverage_id
> >> > beside the code listed above. I need to pass the coverage_id  but I
> >> > don't
> >> > need a hyperlink.
> >>
> >> Well, the link is just an example. How does the user arrive at the
> >> upload form? Whichever way you choose, you're going to have to pass
> >> $coverage_id to your action somehow.
> >>
> >> --
> >> 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.
> >>
> >>
> >
> > --
> > 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.
> >
> >
>
> --
> 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.
>
>
>

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-18 Thread lowpass
Technically, yes. But without knowing the details of what you're
doing, take that with a grain of salt.

You might want to specify the model, for one thing.

On Fri, Jan 18, 2013 at 10:02 AM, Karl Smith  wrote:
> Is it possible to pass the id to my action like this?
>
> UiForm->input('id', array('type' => 'hidden')); ?>
>
>
>
>
> On Thu, Jan 17, 2013 at 5:56 PM, lowpass  wrote:
>>
>> On Wed, Jan 16, 2013 at 5:37 PM, Karl Smith  wrote:
>> >
>> >
>> >>
>> >> > Now as far as my view goes..do I need to add an input for user_id and
>> >> > coverage_id as hidden fields?
>> >>
>> >> The user_id you can add manually after the upload with
>> >> $this->Auth->user('id') but for coverage_id you can either use a
>> >> hidden form field or add that data to the array before saving as well.
>> >> Either way, you'll need to know what the coverage_id is so you should
>> >> pass it to the action in the first place:
>> >>
>> >> echo $this->Html->link(
>> >> 'upload spreadsheet',
>> >> array(
>> >> 'controller' => 'Coverages',
>> >> 'action' => 'processSpreadsheet',
>> >> 'coverage_id' => $xxx
>> >> )
>> >> );
>> >>
>> > Ok...I have a quick questionis there another way to pass the
>> > coverage_id
>> > beside the code listed above. I need to pass the coverage_id  but I
>> > don't
>> > need a hyperlink.
>>
>> Well, the link is just an example. How does the user arrive at the
>> upload form? Whichever way you choose, you're going to have to pass
>> $coverage_id to your action somehow.
>>
>> --
>> 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.
>>
>>
>
> --
> 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.
>
>

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-18 Thread Karl Smith
Is it possible to pass the id to my action like this?

UiForm->input('id', array('type' => 'hidden')); ?>




On Thu, Jan 17, 2013 at 5:56 PM, lowpass  wrote:

> On Wed, Jan 16, 2013 at 5:37 PM, Karl Smith  wrote:
> >
> >
> >>
> >> > Now as far as my view goes..do I need to add an input for user_id and
> >> > coverage_id as hidden fields?
> >>
> >> The user_id you can add manually after the upload with
> >> $this->Auth->user('id') but for coverage_id you can either use a
> >> hidden form field or add that data to the array before saving as well.
> >> Either way, you'll need to know what the coverage_id is so you should
> >> pass it to the action in the first place:
> >>
> >> echo $this->Html->link(
> >> 'upload spreadsheet',
> >> array(
> >> 'controller' => 'Coverages',
> >> 'action' => 'processSpreadsheet',
> >> 'coverage_id' => $xxx
> >> )
> >> );
> >>
> > Ok...I have a quick questionis there another way to pass the
> coverage_id
> > beside the code listed above. I need to pass the coverage_id  but I don't
> > need a hyperlink.
>
> Well, the link is just an example. How does the user arrive at the
> upload form? Whichever way you choose, you're going to have to pass
> $coverage_id to your action somehow.
>
> --
> 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.
>
>
>

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-17 Thread lowpass
On Wed, Jan 16, 2013 at 5:37 PM, Karl Smith  wrote:
>
>
>>
>> > Now as far as my view goes..do I need to add an input for user_id and
>> > coverage_id as hidden fields?
>>
>> The user_id you can add manually after the upload with
>> $this->Auth->user('id') but for coverage_id you can either use a
>> hidden form field or add that data to the array before saving as well.
>> Either way, you'll need to know what the coverage_id is so you should
>> pass it to the action in the first place:
>>
>> echo $this->Html->link(
>> 'upload spreadsheet',
>> array(
>> 'controller' => 'Coverages',
>> 'action' => 'processSpreadsheet',
>> 'coverage_id' => $xxx
>> )
>> );
>>
> Ok...I have a quick questionis there another way to pass the coverage_id
> beside the code listed above. I need to pass the coverage_id  but I don't
> need a hyperlink.

Well, the link is just an example. How does the user arrive at the
upload form? Whichever way you choose, you're going to have to pass
$coverage_id to your action somehow.

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-16 Thread Karl Smith



> > Now as far as my view goes..do I need to add an input for user_id and 
> > coverage_id as hidden fields? 
>
> The user_id you can add manually after the upload with 
> $this->Auth->user('id') but for coverage_id you can either use a 
> hidden form field or add that data to the array before saving as well. 
> Either way, you'll need to know what the coverage_id is so you should 
> pass it to the action in the first place: 
>
> echo $this->Html->link( 
> 'upload spreadsheet', 
> array( 
> 'controller' => 'Coverages', 
> 'action' => 'processSpreadsheet', 
> 'coverage_id' => $xxx 
> ) 
> ); 
>
> Ok...I have a quick questionis there another way to pass the 
coverage_id  beside the code listed above. I need to pass the coverage_id 
 but I don't need a hyperlink. 

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-09 Thread Karl Smith
Ok...I finally got the file to save in the file system correctly. Here is 
my code

$filePath = WWW_ROOT.'/spreadsheet/' . DS . $uploadedFile['name'] ;
move_uploaded_file($uploadedFile['tmp_name'], $filePath);

Now I have to save the meta data associated with file as well as the file 
path. If I need some assistance I will let you guys know. Thank you for 
taking the time to look at my post and helping me! Yall don't know how much 
I appreciate you guys!

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-08 Thread lowpass
You haven't set up your form correctly.

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html

On Tue, Jan 8, 2013 at 11:11 AM, Karl Smith  wrote:
> I am trying to move an uploaded file and Im having trouble with my file
> path. I want to move the uploaded file into Webroot/Spreadsheet. This is how
> I am currently doing it
>
> $filePath = WWW_ROOT . DS .
> 'spreadsheet/'.$this->data['Coverage']['Spreadsheet'];
>
>
> I also get this error message.
> Notice (8): Undefined index:  Coverage [APP/models/coverage.php, line 197]
>
> Any input would be greatly appreciated!
>
> --
> 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.
>
>

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-08 Thread Jeremy Burns | Class Outfit
The $data array does not have a Coverage key.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 8 Jan 2013, at 16:11:48, Karl Smith  wrote:

> I am trying to move an uploaded file and Im having trouble with my file path. 
> I want to move the uploaded file into Webroot/Spreadsheet. This is how I am 
> currently doing it
> 
> $filePath = WWW_ROOT . DS . 
> 'spreadsheet/'.$this->data['Coverage']['Spreadsheet'];
> 
> 
> I also get this error message.
> Notice (8): Undefined index:  Coverage [APP/models/coverage.php, line 197]
> 
> Any input would be greatly appreciated!
> 
> -- 
> 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.
>  
>  

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-08 Thread Karl Smith
I am trying to move an uploaded file and Im having trouble with my file 
path. I want to move the uploaded file into Webroot/Spreadsheet. This is 
how I am currently doing it

$filePath = WWW_ROOT . DS . 
'spreadsheet/'.$this->data['Coverage']['Spreadsheet'];


I also get this error message.
Notice (8): Undefined index:  Coverage [APP/models/coverage.php, line 197]

Any input would be greatly appreciated!

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-07 Thread Karl Smith
I am going to take heed to your message and save my files to my file 
system. The reason being is because my Web Application is going to process 
over 1000 files a year easily, and I don't want to run into performance 
issues in the long run. Also the file size of the uploads will increase in 
size as time goes along. In addition to your advice I also read an article 
called To Blob Or Not To Blob. It can be found 
here. 
I hope this article helps those of you who are in need of a better 
understanding and insight as to how you should save your files.

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-04 Thread lowpass
It's complaining because the insert includes just the modified and
created fields, whereas your table requires that certain columns not
be null. The other columns are not represented because you haven't set
up your code correctly for Cake to include those data.

On Fri, Jan 4, 2013 at 10:21 AM, Karl Smith  wrote:
> Also I forgot to list the errors I have been getting when running my
> script.
>
> Warning (512): SQL Error: 1452: Cannot add or update a child row: a foreign
> key constraint fails (`ilsa_slic`.`spreadsheets`, CONSTRAINT
> `spreadsheets_ibfk_1` FOREIGN KEY (`coverage_id`) REFERENCES `coverages`
> (`id`)) [CORE/cake/libs/model/datasources/dbo_source.php, line 684]
>
> Query: INSERT INTO `spreadsheets` (`modified`, `created`) VALUES
> ('2013-01-04 09:19:05', '2013-01-04 09:19:05')
>
> Warning (2): Cannot modify header information - headers already sent by
> /cake/libs/debugger.php:686) [CORE/cake/libs/controller/controller.php, line
> 742]
>
> --
> 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.
>
>

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-04 Thread lowpass
On Fri, Jan 4, 2013 at 10:14 AM, Karl Smith  wrote:
>
> All I need from this array is the file name. Now with that said, I read alot
> of articles online about saving files to a database. Some people think it is
> better to save to the file system rather than the database. In my case I
> think the best thing for me to do is save the file in my db. My only
> question is "If I save the files to my database will it affect the
> performance of my website over time?"

Well, if you don't expect to have millions of files, or use slave
databases, go ahead and use BLOB. Personally, I'd avoid it.

> Now as far as my view goes..do I need to add an input for user_id and
> coverage_id as hidden fields?

The user_id you can add manually after the upload with
$this->Auth->user('id') but for coverage_id you can either use a
hidden form field or add that data to the array before saving as well.
Either way, you'll need to know what the coverage_id is so you should
pass it to the action in the first place:

echo $this->Html->link(
'upload spreadsheet',
array(
'controller' => 'Coverages',
'action' => 'processSpreadsheet',
'coverage_id' => $xxx
)
);

Router::connect(
'/spreadsheet/upload/:coverage_id', // or whatever suits you
array(
'controller' => 'Coverages',
'action' => 'processSpreadsheet'
),
array(
'coverage_id' => '[0-9]+',
'pass' => array('coverage_id')
)
);


public function processSpreadsheet($coverage_id = null)
{
if ($this->request->is('post'))
{
// handle upload, save, and redirect
}

// If all goes well upon submit you won't reach here
// but will always arrive here on first invocation.
// You should probably check here that $coverage_id isn't empty.

$this->set(compact('coverage_id'));
}


Then create a hidden form field for the Spreadsheet.coverage_id var

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-04 Thread Karl Smith
Also I forgot to list the errors I have been getting when running my 
script.

*Warning* (512): *SQL Error:* 1452: Cannot add or update a child row: a foreign 
key constraint fails (`ilsa_slic`.`spreadsheets`, CONSTRAINT 
`spreadsheets_ibfk_1` FOREIGN KEY (`coverage_id`) REFERENCES `coverages` 
(`id`)) [*CORE/cake/libs/model/datasources/dbo_source.php*, line *684*]

*Query:* INSERT INTO `spreadsheets` (`modified`, `created`) VALUES ('2013-01-04 
09:19:05', '2013-01-04 09:19:05') 

*Warning* (2): Cannot modify header information - headers already sent by 
/cake/libs/debugger.php:686) [*CORE/cake/libs/controller/controller.php*, line 
*742*]

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-04 Thread Karl Smith
Thank you for such a quick response, and yes I can not get the file to save 
in my database. Now to answer some of your questions...yes Coverage can 
only have one spreadsheet, and yes my spreadsheet table has a coverage_id 
field. With that said, I added 

die(debug(uploadedFile)); 
$CoverageId = $this->id;

and this is what I see in the view 

Array
(
[name] => SLT.xls
[type] => application/vnd.ms-excel
[tmp_name] => /tmp/phpH03DuW
[error] => 0
[size] => 36352
)


All I need from this array is the file name. Now with that said, I read alot of 
articles online about saving files to a database. Some people think it is 
better to save to the file system rather than the database. In my case I think 
the best thing for me to do is save the file in my db. My only question is "If 
I save the files to my database will it affect the performance of my website 
over time?" 


Now as far as my view goes..do I need to add an input for user_id and 
coverage_id as hidden fields?

-- 
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: Save Uploaded/Parsed File to Database Table

2013-01-03 Thread lowpass
On Thu, Jan 3, 2013 at 5:33 PM, Karl Smith  wrote:
> Hello,
>I am having some trouble saving an uploaded file to a table in MySQL
> database.

You don't say what the trouble is. The record isn't being saved?


> Also I have added this to my model as well.
>
>  public $hasOne = array(
>   'Spreadsheet' => array(
>   'className' => 'Spreadsheet',
>   'foreignKey' => 'coverage_id',
>   'dependent' => false,
>   'conditions' => '',
>   'fields' => '',
>   'order' => '',
>   'limit' => '',
>   'offset' => '',
>   'exclusive' => '',
>   'finderQuery' => '',
>   'counterQuery' => ''
> );


Can a Coverage have only ONE Spreadsheet? Does the spreadsheets table
have a coverage_id column?

> Also I created a model called Spreadsheet and it is as follows
>
>
>   public $name = 'Spreadsheet';

You can leave out $name if you're using PHP 5.x

>   public $hasone = 'Coverage';

It should be $hasOne. Except in this case you don't want this here
because it should be in $belongsTo.

(In certain circumstances, you can have a model in both, but not using
the same alias.)


>   public $belongsTo = array(
> 'Coverage' => array(
>   'className' => 'Coverage',
>   'foreignKey' => 'coverage_id'
> ),
> 'User' => array(
>   'className' => 'User',
>   'foreignKey' => 'user_id',
>
> )
>   );
>
> };
>
> MySQL database table is as follows

Assuming the spreadsheets table.

> id(varchar)
> filename(varchar)
> file(mediumblob)
> user_id(varchar)
> coverage_id(varchar)
> created(datetime)
> modified(datetime)

id should be INT NOT NULL AUTO_INCREMENT
coverage_id & user_id should be INT NOT NULL

Also, saving files as BLOBs isn't a great idea. You'd be better off
saving the file to the filesystem and storing the path (optionally,
size, type, etc.) in the DB. But leave it as is for now until you can
get the records to save.

>
> This is my model I use to process and save data from the uploaded file:
>
> public function saveSpreadsheet($uploadedFile) {

Place this right at the beginning of the method:

die(debug($uploadedFile));

> $coverageId = $this->id;

Does $this->id have a value?

> exit();

Remove the exit() call.

> Finally here is my view:
>
> UiForm->create(null, array(
> 'type' => 'file',
> 'action' => 'processSpreadsheet',
> 'enctype' => 'multipart/form-data',
>   )); ?>
> UiForm->input('Spreadsheet',
> array(
>   'label' => '',
>
>   'rel'=>'tooltip',
>   'title' => 'Choose a completed SLIC Policy
> Template from your local system to import.',
>   'data-trigger'=>'hover',
>   'type' => 'file',
> )); ?>
>   UiForm->end(array('label' =>'Upload'
> ,'class'=>'btn', 'id'=>'upload-doc' )); ?>

You're not including the Coverage.id nor User.id. Normally, these
would be hidden form fields. However, if you're at all concerned about
someone screwing with the inputs, you can add these to the data later.
I don't see User.id added anywhere, and it's questionable whether
$this->id is set in the Coverage model method.

-- 
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.