Saturday, February 28, 2015

File upload validation

I have a problem with my file upload validation in CakePHP.

When I add a new record with an image upload field...
  • ... image should be required.
  • ... image file extension sould be jpg, png or gif.
When I edit an existing record with an image upload field...
  • ... image is not required.
  • ... when image is choosen: image file extension sould be jpg, png or gif.
Here's my best model code attempt so far:

<?php


class Outlet extends CoasterCmsAppModel
{
   
public $validate = array(
       
'name' => array(
           
'rule' => 'notEmpty', // verplicht
           
'message' => 'Name is required.',
           
'allowEmpty' => true
       
),
       
'intro' => array(
           
'rule' => 'notEmpty', // verplicht
           
'message' => 'Intro is required.'
       
),
       
'photo' => array(
           
'validFileSize' => array( // zelf gekozen naam van de regel
               
'rule' => array('filesize', '>', 0), // verplicht
               
'on' => 'create',
               
'message' => 'Photo is required.'
           
),
           
'validExtension' => array( // zelf gekozen naam van de regel
               
'rule' => array('extension', array('jpg', 'jpeg', 'png', 'gif')),
               
'on' => 'create',
               
'message' => 'Photo has to contain a valid extension (jpg, jpeg, png or gif).'
           
),
           
'validExtension' => array( // zelf gekozen naam van de regel
               
'rule' => array('extension', array('jpg', 'jpeg', 'png', 'gif')),
               
'allowEmpty' => true,
               
'on' => 'update',
               
'message' => 'Photo has to contain a valid extension (jpg, jpeg, png or gif).'
           
)
       
)
   
);
   
   
public function afterValidate()
   
{
        $filename
= $this->data['Outlet']['photo']['name'];
       
       
if (!empty($filename)) {
            move_uploaded_file
($this->data['Outlet']['photo']['tmp_name'], WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);
           
            $this
->set('photo', $filename);
       
} else {
            unset
($this->data['Outlet']['photo']);
       
}
   
}
}


The "add" validation works fine for me. But strange as it is, when I edit a record, I keep getting the error message "Photo has to contain a valid extension (jpg, jpeg, png or gif)."
Somebody who can help me out of this? ;)

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.

Re: Great opportunity - looking for an outstanding CakePHP lead developer for a mathematics education business.

Hi,

Myself interested can u send the details about the project.

On Mon, Feb 23, 2015 at 9:29 PM, <adam@theheartofmathematics.com> wrote:
Hi. We are looking for an outstanding CakePHP lead developer for our mathematics education business. The business is in Los Angeles, and the developer can be here or anywhere. Can anyone recommend someone? Thanks,
Adam

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.

Re: 3.0 Database Error : SQLSTATE[HY000] [14] unable to open database file


 I'm very interest.  which permission? thanks

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

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.

Re: OnChange event wont work in cakephp

Check the syntax of your JQuery selectors.
This does not look right.

$(this:'checked').val() != 3 )

Neither does this:
$('#startdatebox]')
$('

CakePHP Developer Requirement

Hi All,

We are looking for CakePHP developer urgently for Bangalore location. This is a eCommerce product company. experience required within 1 to 5 years. Competitive salary. Please update me resumes on debashis.s@delyver.co.in

Thanks
Debashis

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.

Friday, February 27, 2015

Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

Hi,

Ok I managed solution.

Thanks

On Thursday, January 29, 2015 at 8:26:57 PM UTC+5:30, Cake Developer wrote:
Hi Mark Story,

any help please?

thanks

On Friday, January 23, 2015 at 6:02:46 PM UTC+5:30, Cake Developer wrote:
Hi Josh,

I tried both PlumSearch and Search Plugin in my application and they are not working as expected.

They are adding search arguments in existing conditions in query object.

Failing Situation.
Existing condition has Users.active = 1 and If new condition array has Users.active = 0 so this way merged conditions will have Users.active = 1 AND Users.active = 0 //No Result

I believe it is really a issue.

Thanks in advance.

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.

Re: AppModel Subclass Constructor not called

Correction.... It turns out that the 'with' => false is wrong.....

If using a joinTable ... with needed to be set to the same value as joinTable.

--Charles

On Fri, Feb 27, 2015 at 3:42 PM, Charles Beasley <carmelchas@gmail.com> wrote:
I figured it out!!!!  If you are in the inside-crowd and can add documentation for this problem, please do, assuming I am correct.

I found:

A Model hasAndBelongsToMany association requires an EXPLICIT SETTING ['with' => false] whenever the expectation is that the association model is to be constructed using the Subclass Class constructor versus dynamically constructed using AppModel.

In my case, I added MyModel to the Controller $uses array.  However, there was another MyRelatedModel in the Controller $uses array that was registered by ClassRegistry::init prior to MyModel.  When MyRelatedModel was initialized, it created a dynamic instance of MyModel.  As a result, when ClassRegistry::init was called with MyModel there was already an object registered with the same ClassName and therefore was not recreated.  I had to add 'with=> false to the MyRelatedModel settings for MyModel to ensure AppModel is not used to construct the object.

Please confirm receipt of this information.

Sincerely,

Charles A Beasley





On Thu, Feb 26, 2015 at 3:15 AM, José Lorenzo <jose.zap@gmail.com> wrote:
That means your class is not being loaded, check you wrote the right class name, and that it was placed in the right folder with the correct file name.

If your model is in a plugin, make sure it was loaded using the plugin notation.


On Thursday, February 26, 2015 at 9:06:57 AM UTC+1, Charles Beasley wrote:

I have a model that extends AppModel and overrides the constructor, but the constructor never gets called... instead only the AppModel constructor is called.  

As a result, the belongTo and other associations defined in the class are empty.  However, if I add the following LINE before calling "find", the Model has the defined belongsTo associations and works without error.

 if ( empty($this->ctl->LocationPackage->belongsTo) ) die('LocationPackage Model is corrupted');

Does anyone have any suggestions as to why the above LINE causes the Model to be constructed from the Subclass rather than only call the AppModel constructor?

Thanks in advance.


Sincerely,

Charles

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.


--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.