Help Upload plugin: validation rules

2012-06-30 Thread Matteo Landi
Hi all,
is anybody using Jose Gonzalez's upload plugin [1]?  I have a couple
of open issues regarding its integration inside my web app, but before
filing a bug I wanted to be sure I was doing things the right way.

I attached a couple of validation rules to my Model's attachment
property and they seem to work only while adding a new object to the
database.  If I edit an object, all the rules are processed but they
always return true.

public $actsAs = array(
'Upload.Upload' => array(
'attachment' => array(
'mimetypes' => array(
'application/pdf',
)
)
),
);

public $validate = array(
'attachment' => array(
'valid' => array(
'rule' => array('isValidMimeType', array(), 
false),
'message' => 'File is of an invalid mimetype',
),
),
);

I had a look at the rule code, and on edit operations the function
always exits at its first check:

public function isValidMimeType(&$model, $check, $mimetypes =
array(), $requireUpload = true) {
$field = array_pop(array_keys($check));

if (!empty($check[$field]['remove'])) {
return true;
}

Have you got any idea about this behaviour?  $check[$field]['remove']
in my case gets always initialized to 'M'.  If I comment out the first
check, then the function will always return false (it looks up the
attachment type using $check[$field]['type'] which is still equal to
'M').  It is really strange both lookups return the same string value.


Thanks,
Matteo

[1] https://github.com/josegonzalez/upload

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: i

2012-05-16 Thread Matteo Landi


On May/07, lowpass wrote:
> echo $data['Post']['body'];
> 
> Maybe the question wasn't clear. What exactly do you mean about the
> "right way to display" it?
> 

It is funny how questions arise from dumb errors:  let me explain why.

As I tried to explain in my previous post, I wanted to save raw html tags inside
a blog post, and make the View display them accordinly;  unfortunately, in all
the experiments I made, tags were displayed as raw sequences (asd
instead of an italic asd).  So I complained the list about that.

The problem is that while editing the blog post to add html tags, I only
modified the title field which was rendered inside the View with a command like
this `$this->Html->link($post['Post']['title'], ...)`;  the `link` method
obviously escapes the content of the link label, resulting in html tags
displayed as raw characters :-)

So I edited the post body, and magically html tags were rendered properly!  Mea
culpa!


Cheers,
Matteo


> On Sat, May 5, 2012 at 12:01 PM, Matteo Landi  wrote:
> > Hi everybody,
> >
> > Could you tell me what is the right way to display html formatted content
> > extracted from the database?  Taking the blog tutorial as example, how is
> > possible to let users create posts containing html tags such as `strong`, 
> > `em`,
> > `ul` and so forth?
> >
> >
> > Thanks,
> > Matteo
> >
> > --
> > http://www.matteolandi.net
> >
> > --
> > Our newest site for the community: CakePHP Video Tutorials 
> > http://tv.cakephp.org
> > Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> > others with their CakePHP related questions.
> >
> >
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> > http://groups.google.com/group/cake-php
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Display unescaped html elements

2012-05-05 Thread Matteo Landi
On May/05, Matteo Landi wrote:
> Hi everybody,
> 
> Could you tell me what is the right way to display html formatted content
> extracted from the database?  Taking the blog tutorial as example, how is
> possible to let users create posts containing html tags such as `strong`, 
> `em`,
> `ul` and so forth?
> 
> 
> Thanks,
> Matteo
> 
> -- 
> http://www.matteolandi.net

Excuse me for double posting, but the previous message contained an incomplete
subject.


Cheers,
Matteo

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


i

2012-05-05 Thread Matteo Landi
Hi everybody,

Could you tell me what is the right way to display html formatted content
extracted from the database?  Taking the blog tutorial as example, how is
possible to let users create posts containing html tags such as `strong`, `em`,
`ul` and so forth?


Thanks,
Matteo

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Mock and test uploads

2012-04-28 Thread Matteo Landi
I asked more or less the same question some months ago, and the best solution
I come up with was to populate $_FILES by hand and wrap move_uploaded_file into
a controller method, so that it can be easily mocked inside your tests.


Matteo

On Apr/26, jeremyharris wrote:
> I would take cues from the Media plugin, which uses binary data in some of 
> its testing library.
> 
> Test data: 
> https://github.com/davidpersson/media/blob/next/tests/fixtures/test_data.php
> Where test data is set up: 
> https://github.com/davidpersson/media/blob/next/tests/cases/models/behaviors/base.test.php
> TransferBehavior:  
> https://github.com/davidpersson/media/blob/next/tests/cases/models/behaviors/transfer.test.php
>  
> 
> There are even more tests and data in the MM library within the plugin: 
> https://github.com/davidpersson/media/tree/next/libs/mm/tests
> 
> I don't have any experience with MeioUpload but I imagine changing the 
> paths to the tmp folder will be possible.
> 
> I know this isn't a specific answer but it should give you some good 
> jumping off points.
> 
> -jeremy
> 
> On Thursday, April 26, 2012 7:57:40 AM UTC-7, Thiago Belem wrote:
> >
> > I'm creating a new MeioUpload/Media behavior and I wanted to make it 
> > totally covered by tests...
> >
> > Do you guys have any idea/recomendation/resource about mocking uploads on 
> > CakePHP + PHPUnit?
> >
> > I know I can't just populate $_FILES with my data and expect 
> > is_uploaded_file or move_uploaded_file functions to work.
> >  
> > I don't want to use anoter testing framework like PHPT or something that's 
> > not pure CakePHP and PHPUnit.
> >
> > Regards,
> > --
> > ***Thiago Belem*
> > Desenvolvedor
> > Rio de Janeiro - RJ - Brasil
> >
> > *Assando Sites* - Curso online de *CakePHP*
> > assando-sites.com.br <http://goo.gl/b1EEd>
> >
> > thiagobelem.net
> > cont...@thiagobelem.net
> >
> > *Skype / gTalk **»* thiago.belem.web
> > *LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt
> >
> > 
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: HABTM Fixture

2012-01-23 Thread Matteo Landi


On Jan/22, Thiago Silva wrote:
> Hi,
> 
> How can I create a fixture for a HABTM table?

Imagine an app where users are linked together (friendship): you should have
a Model named `UsersUser' and the fixture `UsersUserFixture'. At this point
inside your tests you should be able able to use the fixture using the name
'app.UsersUser'.


Cheers,
Matteo

> I have tried everything but my tests always say the table is missing.
> 
> Thanks,
> Thiago
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
> 

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Use Vagrant to develop CakePHP applications

2012-01-08 Thread Matteo Landi
Hi guys,

I would like to share with you a small article [1] I wrote which describes how
to use Vagrant to create a customized development virtual environment for
CakePHP: hope this doesn't get tagged as spammy! 

If you have any comments, advices or whatever you want, don't be shy: I will
try my best to answer you.


Regards,
Matteo

[1] http://matteolandi.blogspot.com/2012/01/about-cakephp-and-vagrant.html

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Test controllers throwing exceptions

2012-01-06 Thread Matteo Landi


On Jan/02, AD7six wrote:
> 
> 
> On Dec 28 2011, 4:22 pm, Matteo Landi  wrote:
> > Hi everybody,
> >
> > I have a custom exception handler for all the exceptions raised inside
> > controllers; when I run the controllers' testsuite, I noticed that 
> > exceptions
> > are propagated to the tests instead of being handled by my handler. Is this 
> > the
> > normal behaviour? What if I want to make some assertions on the output of 
> > the
> > exception produced by the handler? Is this out of the scope of 
> > ControllerTest
> > logic or is it ok to test that kind of things inside controller tests?
> 
> It is a bad idea to do what you ask, but if you want to know how -
> just use the source
> https://github.com/cakephp/cakephp/blob/master/lib/Cake/Test/Case/Error/ErrorHandlerTest.php
> 
> Your tests should only be testing for (expected) exceptions being
> thrown - If you want to test your  exception handler logic - you'd do
> that separately, e.g. see link.

That makes sense.

> 
> What does the exception logic that is being missed do? The question
> implies you are misusing exceptions.
> 

Some more context should help: I'm working on a REST application in which,
before switching to exceptions, each time an error was returned, I used to
create arrays objects containing such error messages and then let the _View_
transform the PHP object into a JSON or XML one.

Now with exceptions it seems to me that the controller logic is simplified
a lot: instead of all the < )>> logic, I can
simply call the the method interest and let it throw the specific exception if
needed; moreover, I can use a custom exception handler able to understand the
kind or request (JSON or XML) and create the well-formatted error page.

Am I doing something wrong or is this a good way to do things? Thanks for the
advices.


Matteo

> AD
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
> 

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: campo id

2012-01-06 Thread Matteo Landi

On Jan/05, Laerte M. Rodrigues wrote:
> se a tabela possui chave primaria no modelo declare
> 
> var $primary = "nomeCampo";
> 
> assim, será  a chave primária, caso seja composta, utilize array
> 
> var $primary  = array("Campo1","Campo2");
> 
> Em 5 de janeiro de 2012 16:14, Filippi Rizzi 
> escreveu:
> 
> > Olá! Trabalho com o cake a alguns anos, e sempre utilizei como pk das
> > tabelas o id.. porem recebi uma modelagem de um bd no qual as tabelas
> > não possuem id.. gostaria de saber se alguem trabalha assim utilizando
> > o cake e ou ja tentou trabalhar assim.. Obrigado.
> >
> > --
> > Our newest site for the community: CakePHP Video Tutorials
> > http://tv.cakephp.org
> > Check out the new CakePHP Questions site http://ask.cakephp.org and help
> > others with their CakePHP related questions.
> >
> >
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group
> > at http://groups.google.com/group/cake-php
> >
> 
Please, speak in English.


Cheers,
Matteo

> 
> -- 
> Grato,
> 
> Laerte Mateus Rodrigues
> Mestrando em informática (PUC Minas)
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: REST Error Handling

2012-01-03 Thread Matteo Landi


On Jan/02, Will wrote:
> Hi all,
> 
> I'm looking for a way to return a generic error every time something
> goes wrong with a REST request.  So for example, I would like to
> return a simple, XML response like:
> 
> 
> There was a problem processing your request.
> 
> 
> Anytime something goes wrong when something is accessed via REST (e.g.
> the template is in the View/$ControllerName/xml folder) but NOT when
> the page is accessed normally (the template is in the View/
> $ControllerName/ folder).  Is there way way to do this in Cake?  Or
> perhaps a smarter way to achieve similar functionality?

What about install a custom exception handler which outputs your formatted
message on screen? This ways you will be able to handle both core and custom
exceptions so that they are rendered as you whish.


Regards,
Matteo

> 
> Thanks,
> 
> -Will
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
> 

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Extend ControllerTestCase

2012-01-02 Thread Matteo Landi
Bump!

On Dec/28, Matteo Landi wrote:
> Excuse me for bringing up this old topic, but I have one more question.
> 
> My TestController wrapper object contains a method which tests the
> authentication layer (it's a custom layer, not the one shipped within 
> cakephp);
> consequently all the controllers' tests can easily issue
> $this->testAuthKeys(...) and check whether the authentication layer has been
> correctly implemented by tested controllers.
> 
> The problem is that if I assign to the aforementioned function the name
> ``testAuthLayer'' (or ``test*'' in general), the testsuite will try and test
> the method itself. Is there a way to avoid this? (other than workarounds like
> $this->_testAuthKeys..)
> 
> 
> Regards,
> Matteo
> 
> On Dec/11, Matteo Landi wrote:
> > Thank for the fast response:
> > - placed the wrapper inside app/Lib/Test
> > - added App::uses('MyWrapper...', 'Test') on top of all my controllers tests
> > - changed 'extends ControllerTestCase' to 'extends MyWrapper...'
> > et voila!
> > 
> > 
> > Regards,
> > Matteo
> > 
> > On Sun, Dec 11, 2011 at 11:54 AM, euromark  
> > wrote:
> > > also create a package name for it (e.g. Test)
> > >
> > > App::uses('My...', 'Test');
> > > App::uses('My...', 'PluginName.Test');
> > >
> > >
> > > On 11 Dez., 11:52, euromark  wrote:
> > >> I place mine in the Lib folder
> > >> either plugin (cross app) or app Lib folder.
> > >> in 2.0 you can
> > >>
> > >> On 11 Dez., 11:30, Matteo Landi  wrote:
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> > Hi,
> > >> > where is the right place to put a class which extends and add some
> > >> > functionalities to ControllerTestCase so that I can it inside all my
> > >> > controllers tests? Imagine all my controllers tests implement a
> > >> > testAction wrapper: it would be handy to extend ControllerTestCase,
> > >> > implement such wrapper in there, and finally make all my tests extend
> > >> > MyControllerTestCase instead of the legacy one.
> > >>
> > >> > Regards,
> > >> > Matteo
> > >>
> > >> > --http://www.matteolandi.net/
> > >
> > > --
> > > Our newest site for the community: CakePHP Video Tutorials 
> > > http://tv.cakephp.org
> > > Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> > > others with their CakePHP related questions.
> > >
> > >
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > > at http://groups.google.com/group/cake-php
> > >
> > 
> > 
> > 
> > -- 
> > http://www.matteolandi.net/
> 
> -- 
> http://www.matteolandi.net

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Test controllers throwing exceptions

2012-01-02 Thread Matteo Landi
Bump!

On Dec/28, Matteo Landi wrote:
> Hi everybody,
> 
> I have a custom exception handler for all the exceptions raised inside
> controllers; when I run the controllers' testsuite, I noticed that exceptions
> are propagated to the tests instead of being handled by my handler. Is this 
> the
> normal behaviour? What if I want to make some assertions on the output of the
> exception produced by the handler? Is this out of the scope of ControllerTest
> logic or is it ok to test that kind of things inside controller tests?
> 
> 
> Regards,
> Matteo
> 
> -- 
> http://www.matteolandi.net

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Test controllers throwing exceptions

2011-12-28 Thread Matteo Landi
Hi everybody,

I have a custom exception handler for all the exceptions raised inside
controllers; when I run the controllers' testsuite, I noticed that exceptions
are propagated to the tests instead of being handled by my handler. Is this the
normal behaviour? What if I want to make some assertions on the output of the
exception produced by the handler? Is this out of the scope of ControllerTest
logic or is it ok to test that kind of things inside controller tests?


Regards,
Matteo

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Extend ControllerTestCase

2011-12-28 Thread Matteo Landi
Excuse me for bringing up this old topic, but I have one more question.

My TestController wrapper object contains a method which tests the
authentication layer (it's a custom layer, not the one shipped within cakephp);
consequently all the controllers' tests can easily issue
$this->testAuthKeys(...) and check whether the authentication layer has been
correctly implemented by tested controllers.

The problem is that if I assign to the aforementioned function the name
``testAuthLayer'' (or ``test*'' in general), the testsuite will try and test
the method itself. Is there a way to avoid this? (other than workarounds like
$this->_testAuthKeys..)


Regards,
Matteo

On Dec/11, Matteo Landi wrote:
> Thank for the fast response:
> - placed the wrapper inside app/Lib/Test
> - added App::uses('MyWrapper...', 'Test') on top of all my controllers tests
> - changed 'extends ControllerTestCase' to 'extends MyWrapper...'
> et voila!
> 
> 
> Regards,
> Matteo
> 
> On Sun, Dec 11, 2011 at 11:54 AM, euromark  wrote:
> > also create a package name for it (e.g. Test)
> >
> > App::uses('My...', 'Test');
> > App::uses('My...', 'PluginName.Test');
> >
> >
> > On 11 Dez., 11:52, euromark  wrote:
> >> I place mine in the Lib folder
> >> either plugin (cross app) or app Lib folder.
> >> in 2.0 you can
> >>
> >> On 11 Dez., 11:30, Matteo Landi  wrote:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> > Hi,
> >> > where is the right place to put a class which extends and add some
> >> > functionalities to ControllerTestCase so that I can it inside all my
> >> > controllers tests? Imagine all my controllers tests implement a
> >> > testAction wrapper: it would be handy to extend ControllerTestCase,
> >> > implement such wrapper in there, and finally make all my tests extend
> >> > MyControllerTestCase instead of the legacy one.
> >>
> >> > Regards,
> >> > Matteo
> >>
> >> > --http://www.matteolandi.net/
> >
> > --
> > Our newest site for the community: CakePHP Video Tutorials 
> > http://tv.cakephp.org
> > Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> > others with their CakePHP related questions.
> >
> >
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> > http://groups.google.com/group/cake-php
> >
> 
> 
> 
> -- 
> http://www.matteolandi.net/

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Problem with transaction in version 2.0

2011-12-21 Thread Matteo Landi
On Wed, Dec 21, 2011 at 9:52 AM, socrates  wrote:
>
> Thanks all for the help, I solved in this way:

Are you telling us that now transactions are working properly?

> 1) I move the code form the controller to the model. (I don't really
> know if this help!)
> 2) I used the Datasource to start the transaction. (Like explained in
> the docs)
> 3) I commit or rollback with the datasource, but the SQLLog in the
> page shows only the query, and no trace of the transaction SQL code.

That's strange even if I think it is possible cakephp will not log
everything; however, maybe some cakephp-sql expert guys would shed
some light on the subject.


Matteo

>
> Code:
>
> inside the Model
>   [...]
>
>  $ds = this->getDataSource();
>  $ds->begin($this);
>  $result = $this->saveAssociated('params');
>  if ($result) {
>    $ds->commit($this); // in the doc there are no trace of this, that
> i have to pass like parameter the refernce to $this.
>  } else {
>    $ds->rollback($this);
>  }
> ?>
>
> --
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Problem with transaction in version 2.0

2011-12-20 Thread Matteo Landi


On 12/20, socrates wrote:
> No in fact it does not solve my problem, but maybe i don't understand very 
> well.
> This is my piece of code:
> 
> $this->StadiobingoBet->query('SET AUTOCOMMIT = OFF');
> debug($this->StadiobingoBet->begin());
> if (!$this->StadiobingoBet->saveAll(null, array('atomic' => true, 
> 'validate' => false))) {
>   $this->StadiobingoBet->commit();
> } else {
>   $this->StadiobingoBet->rollback();
> }
> 

I seem to remember that model's commit and rollback functions are deprecated,
but I could be wrong; anyway, the book [1] suggests to invoke those methods on
the dataSource object (I'm not at home, so I can't confirm this is causing the
problem): give it a try.

If that does not work, try transactions inside MySQL shell, and if that works,
then analyze all the queries executed by cakephp.


Matteo

[1] 
http://book.cakephp.org/2.0/en/models/transactions.html?highlight=transactions

> If the query of save associated goes well, it have to rollback, but it does 
> not.
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Problem with transaction in version 2.0

2011-12-20 Thread Matteo Landi


On 12/20, socrates wrote:
> I found a possible solution here! Transaction Commit and 
> Rollback<http://ask.cakephp.org/questions/view/rollback_and_commit>
> Tnx.

Let us know if that solves your problems.


Regards,
Matteo

> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: CakePHP and Sqlite

2011-12-19 Thread Matteo Landi

On 12/19, NaeiKinDus wrote:
> Hi there,
> 
> Sorry for the thread hijacking / bump, but a little more information
> on this topic could help some people. Is there anything else to do/
> check to get it working ? In my case, CakePHP cannot connect to the
> database, even though I have the PDO installed and configured to work
> with SQLite (& SQLite2).
> Sample of my database.php config:
> 
> public $default = array(
> 'datasource' => 'Database/Sqlite',
> //'database' => '/var/www/app/Config/
> db_name',
> 'database' => 'db_name',
> );
> 
> I tried both values for the database param, the first one referring to
> the full path of the db, the second to the db_name database being
> located in the webroot and the Config folders. The db_name file was
> created with one empty table using SQLite3 CLI.

What about file permissions? Make sure created database can be modified by the
cakephp process.


Matteo

-- 
http://www.matteolandi.net

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Locked tables in transactions

2011-12-16 Thread Matteo Landi
Bump!

On Tue, Dec 13, 2011 at 12:18 AM, Matteo Landi  wrote:
> Hi everybody,
>
> could someone tell me what tables get locked during an explicit
> CakePHP transaction?
>
> $dataSource = $this->getDataSource();
> $dataSource->begin();
> // transaction logic
> $dataSource->commit(); // or $dataSource->rollback();
>
> Imagine to update a Post if and only if it exists; we can use
> transactions (a bit overkill, but was worth the example) and implement
> a method like this:
>
> public function update($data) {
>    $dataSource = $this->getDataSource();
>    $dataSource->begin();
>
>    $this->id = $data['id'];
>    if (!$this->exists() || !$this->save($data)) {
>        $dataSource->rollback();
>        return false;
>    }
>
>    $dataSource->commit(); // or $dataSource->rollback();
> }
>
> Are all the tables linked to Post model, locked inside the
> transaction? If so, how can a developer avoid that? Maybe writing
> straight SQL statements?
>
>
> Regards,
> Matteo
>
> --
> http://www.matteolandi.net/



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Testing image upload

2011-12-13 Thread Matteo Landi
On Tue, Dec 13, 2011 at 3:49 AM, leigh  wrote:
> Hello Matteo,
>
> Looks like the only way is to wrap the functions, on a second look
> Sebastian Bergmann's php-test-helpers is only for user created
> functions.
>
> kind regards,
>
> Leigh

Leigh, thanks for the hint.

I made a quick search on Google and found a Stackoverflow discussion
in which a user describe the "wrapper" solution, but I don't get how
to override model isUplaodedFile and moveUploadedFile methods from the
within the test-controller class: any advices?


regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Locked tables in transactions

2011-12-12 Thread Matteo Landi
Hi everybody,

could someone tell me what tables get locked during an explicit
CakePHP transaction?

$dataSource = $this->getDataSource();
$dataSource->begin();
// transaction logic
$dataSource->commit(); // or $dataSource->rollback();

Imagine to update a Post if and only if it exists; we can use
transactions (a bit overkill, but was worth the example) and implement
a method like this:

public function update($data) {
$dataSource = $this->getDataSource();
$dataSource->begin();

$this->id = $data['id'];
if (!$this->exists() || !$this->save($data)) {
$dataSource->rollback();
return false;
}

$dataSource->commit(); // or $dataSource->rollback();
}

Are all the tables linked to Post model, locked inside the
transaction? If so, how can a developer avoid that? Maybe writing
straight SQL statements?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Testing image upload

2011-12-12 Thread Matteo Landi
On Mon, Dec 12, 2011 at 4:46 AM, leigh  wrote:
> Hi Matteo,
>
> Wrap move_uploaded_file and is_uploaded_file inside the controller
>
> function moveUploadedFIle($filename, $destination) {
>  return move_uploaded_file($filename, $destination);
> }
>
> function moveUploadedFIle($filename, $destination) {
>  return is_uploaded_file($filename, $destination);
> }
>
> Then inside your testController override them.
>
> class TestPostsController extends postsController {
>
>  protected function isUploadedFile($filename) {
>   return true;
>  }
>  protected function moveUploadedFile($filename, $destination) {
>   return true;
>  }
>

You are assuming that my controllers tests extend controllers and not,
as usual, CakeControllerTest. However, do I really need to do
something similar to test image uploading? Is this supported or not?


Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Extend ControllerTestCase

2011-12-11 Thread Matteo Landi
Thank for the fast response:
- placed the wrapper inside app/Lib/Test
- added App::uses('MyWrapper...', 'Test') on top of all my controllers tests
- changed 'extends ControllerTestCase' to 'extends MyWrapper...'
et voila!


Regards,
Matteo

On Sun, Dec 11, 2011 at 11:54 AM, euromark  wrote:
> also create a package name for it (e.g. Test)
>
> App::uses('My...', 'Test');
> App::uses('My...', 'PluginName.Test');
>
>
> On 11 Dez., 11:52, euromark  wrote:
>> I place mine in the Lib folder
>> either plugin (cross app) or app Lib folder.
>> in 2.0 you can
>>
>> On 11 Dez., 11:30, Matteo Landi  wrote:
>>
>>
>>
>>
>>
>>
>>
>> > Hi,
>> > where is the right place to put a class which extends and add some
>> > functionalities to ControllerTestCase so that I can it inside all my
>> > controllers tests? Imagine all my controllers tests implement a
>> > testAction wrapper: it would be handy to extend ControllerTestCase,
>> > implement such wrapper in there, and finally make all my tests extend
>> > MyControllerTestCase instead of the legacy one.
>>
>> > Regards,
>> > Matteo
>>
>> > --http://www.matteolandi.net/
>
> --
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Testing image upload

2011-12-11 Thread Matteo Landi
bump!

On Sat, Dec 3, 2011 at 8:01 PM, Matteo Landi  wrote:
> Hi list,
> what is the right way (if any) to test a controller which handles file
> uploads? At the moment I fill $_FILES with an array containing the
> fields expected by the controller (i.e. 'tmp_name', 'size', etc.) and
> then invoke testAction() passing $_FILES as well, but the whole
> mechanism fails when issuing move_uploaded_file() (is_uploaded_file()
> with provided 'tmp_name' is actually returning false). What do you
> suggest?
>
>
> Regards,
> Matteo
>
> --
> http://www.matteolandi.net/



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Extend ControllerTestCase

2011-12-11 Thread Matteo Landi
Hi,
where is the right place to put a class which extends and add some
functionalities to ControllerTestCase so that I can it inside all my
controllers tests? Imagine all my controllers tests implement a
testAction wrapper: it would be handy to extend ControllerTestCase,
implement such wrapper in there, and finally make all my tests extend
MyControllerTestCase instead of the legacy one.


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Edit an object without creating it

2011-12-08 Thread Matteo Landi
Thank you guys for the precious information you shared with me.

Reading the link euromark posted, I found a lot of similarities with
our controller implementation: first of all we call a function
validateInput (we are better off changing its name to something more
compatible with cakephp use of validate) to parse input data (GET,
POST or PUT) and make sure that some fields are in there and others
not; then we call allowRequest which guarantees us that the current
request could be accepted by the engine (it is coming from a trusted
application and if tries to view/edit private data, it checks if the
owner of that information is the one requesting it); it calls models
method to save/edit/read records from the database; finally (we should
think of a better way to implement this in order to not to break the
MVC paradigm) data fetched from the model is reformatted (calling
Model specific methods) so that json and xml views can easily convert
them to json and xml objects.


Cheers,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Edit an object without creating it

2011-12-07 Thread Matteo Landi
> your definition of validate appears to differ from the frameworks. The
> conclusion I was leading you towards was to always start with the code
> bake gives you - and you are not.

You are right, in the previous sentence with ``validate'' I meant I
needed to make sure that given id points to a record of the database.
I have not taken into account the possibility of using bake because
I'm working on a REST application which has nothing to do with forms
of flash messages, so I decided to create each controller from
scratch; however I could give it a try and see how generated
controllers look like.

>
>> I think
>> I will put that logic inside the beforeSave callback in order to keep
>> controllers as simple as possible.
>
> Doing that doesn't make any sense, you're planning to put something in
> a model that doesn't belong there.

The only problem I see with what I proposed before, is that it would
be not easy at all to distinguish between save operations trying to
create a new record, and edit operations trying to edit an existing
one; probably a new Model->update method would fix that: add
controllers would invoke save to create a new object, while edit
controllers would call the update method (which would fail if there is
no record with given id). Do you think this solution is breaking the
MVC paradigm?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Edit an object without creating it

2011-12-07 Thread Matteo Landi
On Wed, Dec 7, 2011 at 9:35 AM, AD7six  wrote:
>
>
> On Dec 3, 7:43 pm, Matteo Landi  wrote:
>> Hi everybody,
>> is there a way, given an id, to invoke Model->save() (or anything
>> else) to update the relative record if and only if the id is valid?
>
> yes, you only call save if the id exists. Use exists or if you prefer
> count to check.
>
>> Imagine I want to edit a Post and change its body; if I erroneously
>> call the edit action passing an id which does not exist,
>> Model->save($data) will create a new Post with the wrong id.
>
> As someone else has already pointed out if you use bake to generate
> your code that cannot happen.
>
>>
>> The following is the implementation of the edit action (very similar
>> to the add one):
>>
>> // controller
>> public edit() {
>>     ...
>>     $data = validateInput(...);
>
> why are you validating in the controller? Or does validateinput do
> something different than data validation?
>
>>     if ($this->Post->save($data))
>>         // ok
>>     else
>>         // something went wrong
>>     ...
>>
>> }
>
> which version of cake are you using - the above looks like you're
> probably using 1.3

I'm using with 2.0 but I started developing with CakePHP a couple of
months ago; anyway, why are you asking this? Do you see something
wrong in the action logic presented above?

>
>>
>> What is the right way to avoid this?
>
> using bake, or referring to an example generated that used bake, such
> that your edit action only generates an error if the id doesn't exist.

bake or not bake, error or not error, we arrived to the conclusione
that I have to validate the id before invoking Model->save(); I think
I will put that logic inside the beforeSave callback in order to keep
controllers as simple as possible.


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Edit an object without creating it

2011-12-07 Thread Matteo Landi
On Wed, Dec 7, 2011 at 9:03 AM, Geoff Douglas  wrote:
> I think what you are looking for is the Model->exists() method. Please see a
> baked Cake 2.0 edit method.
>
> /**
>  * edit method
>  *
>  * @param string $id
>  * @return void
>  */
> public function edit($id = null) {
> $this->{YourModel}->id = $id;
> if (!$this->{YourModel}->exists()) {
> throw new NotFoundException(__('Invalid {YourModel} record'));
> }
> if ($this->request->is('post') || $this->request->is('put')) {
> if ($this->{YourModel}->save($this->request->data)) {
> $this->Session->setFlash(__('The {YourModel} record has been saved'));
> $this->redirect(array('action' => 'index'));
> } else {
> $this->Session->setFlash(__('The {YourModel} record could not be saved.
> Please, try again.'));
> }
> } else {
> $this->request->data = $this->{YourModel}->read(null, $id);
> }
> }

Or even better put this logic inside the Model->beforeSave() callback
and leave the controllers unmodified.


Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Edit an object without creating it

2011-12-06 Thread Matteo Landi
On Tue, Dec 6, 2011 at 8:48 PM, phpMagpie  wrote:
> You gave no indication this was to be a REST enabled application and as 99%
> of apps are not REST then the replies were valid.

I gave no indication because the problem I mentioned apply on both
REST and not-REST applications.

Imagine you are creating a webapp for blog posts; to insert a new
entry you would fill a form (title and body) and then sumbit those
data to the right URI (posts/add). Now, to edit an already submitted
post, you would fill a form (similar to the previous but containing
the post id as an hidden field) and then submit the data to the server
(posts/edit). You will agree with me that the edit action, with or
without the form, is still in need of validating the input id: update
the post if valid, otherwise discard the request. Then my question is:
CakePHP has something which updates a record only if provided id is
valid or should I have to wrap the aforementioned logic?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Edit an object without creating it

2011-12-06 Thread Matteo Landi
On Mon, Dec 5, 2011 at 1:54 PM, phpMagpie  wrote:
> You should never get to the point of editing a record's data before first
> displaying a form for that record.  It's at this point you should check if a
> record with the given ID exists and act accordingly.

I don't agree with you. You can't make assumptions about client side
data: what if users try to communicate with your application without
using a browser (e.g. your app is REST enabled)? He already knows the
format of the data the server is expecting hence he tries to send a
request without filling the form..


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Testing image upload

2011-12-03 Thread Matteo Landi
Hi list,
what is the right way (if any) to test a controller which handles file
uploads? At the moment I fill $_FILES with an array containing the
fields expected by the controller (i.e. 'tmp_name', 'size', etc.) and
then invoke testAction() passing $_FILES as well, but the whole
mechanism fails when issuing move_uploaded_file() (is_uploaded_file()
with provided 'tmp_name' is actually returning false). What do you
suggest?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Edit an object without creating it

2011-12-03 Thread Matteo Landi
Hi everybody,
is there a way, given an id, to invoke Model->save() (or anything
else) to update the relative record if and only if the id is valid?
Imagine I want to edit a Post and change its body; if I erroneously
call the edit action passing an id which does not exist,
Model->save($data) will create a new Post with the wrong id.

The following is the implementation of the edit action (very similar
to the add one):

// controller
public edit() {
...
$data = validateInput(...);
if ($this->Post->save($data))
// ok
else
// something went wrong
...
}

What is the right way to avoid this? Should I have to create a helper
function (like the one below) which validates the id and then update
the record and then use save inside the add action, and update inside
the edit one?

// model
public update($data) {
if (!$this->read(null, $data['id']))
return;
$this->save($data);
}


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Using REST In CakePHP 2.0

2011-11-15 Thread Matteo Landi
--
http://www.matteolandi.net
On Nov 15, 2011 6:09 PM, "Will" <000w.s.s@gmail.com> wrote:

> For the benefit of anyone else reading this, you can format the result
> of a call to $this->Model->find('all) with the following function:
>
> /** function _get_xml_array
>   *
>   *  This function takes in an input from $this->Model->find() and
> reutrns an array
>   *  that is properly strucutred so that CakePHP's Xml Utility can
> format it.
>   *
>   *  @author Will Simpson
>   *  @access private
>   *  @param $input -- An array from $this->Model->find()
>   *  @return $output -- An array in the following format:
>   *  array(
>   *   'tags' => array(
>   *   'tag' => array(
>   *array(
>   *   'id' => '1',
>   *   'name' => 'defect'
>   *   ),
>   *   array(
>   *   'id' => '2',
>   *   'name' => 'enhancement'
>   *   )
>   *   )
>   *   )
>   *   );
>   *
>   */
>  private function _get_xml_array($input,$plural=NULL,$singular=NULL)
> {
>$output = array();
>
>if(count($input) == 0)
>  return $output;
>
>if($plural == NULL)
>  $plural = $this->name;
>
>if($singular == NULL)
>  $singular = key($input[0]);
>
>
>foreach($input as $i){
>  $output[] = $i[$singular];
>}
>$output = array($plural=>array($singular=>$output));
>return $output;
>  }
>
> Basically, the Xml Utility is expecting an array with one element that
> contains another array of one element that contains an array of many
> elements.  Using my Employee model as an example, the correct
> structure would be:
>
> Array
> (
>[Employees] => Array
>(
>[Employee] => Array
>(
>[0] => Array
>(
>[id] => 1
>[emp_name] => Will Simpson
>[emp_job] => Web Developer
>)
>
>[1] => Array
>(
>[id] => 2
>[emp_name] => Joey Vickers
>[emp_job] => Random Guy
>)
>
>)
>
>)
>
> )
>
> If you use this structure, you don't need to be any "plural" tags in
> your xml view like to book describes.  The view would simply be:
>
> 
>  $xml = Xml::build($employees_xml);
>  echo $xml->saveXML();
> ?>
>
>
> With no additional tags around it.  Also make sure that you have the
> latest version of CakePHP (2.0.3).  I think there is a hiccup in the
> RequestHandler in earlier versions that is causing the top-level xml
> tag to be repeated.
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
>
>

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: CakePHP and Sqlite

2011-11-13 Thread Matteo Landi
On Sun, Nov 13, 2011 at 5:25 AM, zer0_gravity  wrote:
> Having trouble setting up CakePHP to work with Sqlite? could you
> explain or point me to where I can get info in rewards to this.
>
> thanks
>

FWIW a couple of weeks ago I wrote a mini-tutorial about how to setup
a SQLite connection within CakePHP application; if you are interested,
check it out: 
http://matteolandi.blogspot.com/2011/10/about-cakephp-and-sqlite.html


Cheers,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: running tests from the command line

2011-10-28 Thread Matteo Landi
Hi,

I don't know about plugins but on my machine I am able to run app
tests with `cake testsuite app AllController' (supposed you have a
test inside 'app/Test/Case/AllControllerTest'), or `cake testsuite app
Case/PostsController' (supposed you have
'app/Test/Case/Controller/PostsControllerTest').


Cheers,
Matteo

On Fri, Oct 28, 2011 at 11:56 AM, euromark  wrote:
> how can one run tests from the command line?
> the core tests are listed with
>    cake testsuite core
> so far so good
>
> but the app tests do not show
> especially tests in a plugin I cannot get to list or call
>    cake testsuite app Tools.AllCakeTests
> does not 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Multiple testAction inside a single test

2011-10-22 Thread Matteo Landi
Bug resolved: 
https://github.com/cakephp/cakephp/commit/c5ca10ca6932b76f505fec39f6e78b34dfcc5b9e


Cheers,
Matteo

On Fri, Oct 21, 2011 at 11:38 AM, Matteo Landi  wrote:
> Hi everybody,
>
> I'm implementing a test for a controller, and I'm experiencing a
> strange problem: it seems that if I call ``testAction`` multiple time
> inside the same test function, assertions start to fail as if requests
> were not properly sent to controllers.
>
> The example below shows a successful test; as you can notice I created
> multiple test functions for the same view, and in each I call
> ``testAction`` exactly once.
>
> class UsersControllerTest extends ControllerTestCase {
>        public $fixtures = array('app.user');
>
>        /**
>         * Helper function which automatically converts the output of an 
> action to
>         * a JSON object.
>         */
>        public function getJsonResult($url, $args = array()) {
>                $data = $this->testAction($url, $args);
>                return json_decode($data, true);
>        }
>
>
>        public function testJsonView() {
>                // Empty id
>                $result = $this->getJsonResult('/users.json', array(
>                        'data' => array(),
>                        'method' => 'GET',
>                        'return' => 'contents'
>                ));
>                $this->assertType('array', $result);
>                $this->assertArrayHasKey('error', $result);
>                $this->assertRegExp('/[rR]equired.*id/', $result['error']);
>        }
>
>        public function testJsonView1() {
>                // Invalid id
>                $result = $this->getJsonResult('/users.json', array(
>                        'data' => array('id' => 'a'),
>                        'method' => 'GET',
>                        'return' => 'contents'
>                ));
>                $this->assertNull($result);
>        }
>
>        public function testJsonView2() {
>                // Ok
>                $result = $this->getJsonResult('/users.json', array(
>                        'data' => array('id' => 1),
>                        'method' => 'GET',
>                        'return' => 'contents'
>                ));
>                $this->assertType('array', $result);
>                $this->assertArrayHasKey('id', $result);
>                $this->assertEquals(1, $result['id']);
>        }
> }
>
> Now, if move all those tests inside the same function (like presented
> below), I get assertion errors after the third call ``testAction``.
>
> class UsersControllerTest extends ControllerTestCase {
>        public $fixtures = array('app.user');
>
>        /**
>         * Helper function which automatically converts the output of an 
> action to
>         * a JSON object.
>         */
>        public function getJsonResult($url, $args = array()) {
>                $data = $this->testAction($url, $args);
>                return json_decode($data, true);
>        }
>
>
>        public function testJsonView() {
>                // Empty id
>                $result = $this->getJsonResult('/users.json', array(
>                        'data' => array(),
>                        'method' => 'GET',
>                        'return' => 'contents'
>                ));
>                $this->assertType('array', $result);
>                $this->assertArrayHasKey('error', $result);
>                $this->assertRegExp('/[rR]equired.*id/', $result['error']);
>
>                // Invalid id
>                $result = $this->getJsonResult('/users.json', array(
>                        'data' => array('id' => 'a'),
>                        'method' => 'GET',
>                        'return' => 'contents'
>                ));
>                $this->assertNull($result);
>
>                // Ok
>                $result = $this->getJsonResult('/users.json', array(
>                        'data' => array('id' => 1),
>                        'method' => 'GET',
>                        'return' => 'contents'
>                ));
>                $this->assertType('array', $result);
>                $this->assertArrayHasKey('id', $result);
>                $this->assertEquals(1, $result['id']);
>        }
> }
>
> Are there any constrains in calling ``testAction`` inside a test
> method? It seems that after the first call , the function starts to
> return array().
>
>
> Regards,
> Matteo
>
> --
> http://www.matteolandi.net/
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Multiple testAction inside a single test

2011-10-21 Thread Matteo Landi
Hi everybody,

I'm implementing a test for a controller, and I'm experiencing a
strange problem: it seems that if I call ``testAction`` multiple time
inside the same test function, assertions start to fail as if requests
were not properly sent to controllers.

The example below shows a successful test; as you can notice I created
multiple test functions for the same view, and in each I call
``testAction`` exactly once.

class UsersControllerTest extends ControllerTestCase {
public $fixtures = array('app.user');

/**
 * Helper function which automatically converts the output of an action 
to
 * a JSON object.
 */
public function getJsonResult($url, $args = array()) {
$data = $this->testAction($url, $args);
return json_decode($data, true);
}


public function testJsonView() {
// Empty id
$result = $this->getJsonResult('/users.json', array(
'data' => array(),
'method' => 'GET',
'return' => 'contents'
));
$this->assertType('array', $result);
$this->assertArrayHasKey('error', $result);
$this->assertRegExp('/[rR]equired.*id/', $result['error']);
}

public function testJsonView1() {
// Invalid id
$result = $this->getJsonResult('/users.json', array(
'data' => array('id' => 'a'),
'method' => 'GET',
'return' => 'contents'
));
$this->assertNull($result);
}

public function testJsonView2() {
// Ok
$result = $this->getJsonResult('/users.json', array(
'data' => array('id' => 1),
'method' => 'GET',
'return' => 'contents'
));
$this->assertType('array', $result);
$this->assertArrayHasKey('id', $result);
$this->assertEquals(1, $result['id']);
}
}

Now, if move all those tests inside the same function (like presented
below), I get assertion errors after the third call ``testAction``.

class UsersControllerTest extends ControllerTestCase {
public $fixtures = array('app.user');

/**
 * Helper function which automatically converts the output of an action 
to
 * a JSON object.
 */
public function getJsonResult($url, $args = array()) {
$data = $this->testAction($url, $args);
return json_decode($data, true);
}


public function testJsonView() {
// Empty id
$result = $this->getJsonResult('/users.json', array(
'data' => array(),
'method' => 'GET',
'return' => 'contents'
));
$this->assertType('array', $result);
$this->assertArrayHasKey('error', $result);
$this->assertRegExp('/[rR]equired.*id/', $result['error']);

// Invalid id
$result = $this->getJsonResult('/users.json', array(
'data' => array('id' => 'a'),
'method' => 'GET',
'return' => 'contents'
));
$this->assertNull($result);

// Ok
$result = $this->getJsonResult('/users.json', array(
'data' => array('id' => 1),
'method' => 'GET',
'return' => 'contents'
));
$this->assertType('array', $result);
$this->assertArrayHasKey('id', $result);
$this->assertEquals(1, $result['id']);
}
}

Are there any constrains in calling ``testAction`` inside a test
method? It seems that after the first call , the function starts to
return array().


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: How do you go about making a ReST service filterable (search via ReST)

2011-10-21 Thread Matteo Landi
On Fri, Oct 21, 2011 at 2:38 AM, Greg  wrote:
> Still a bit stuck here with ReST. I have the index displaying as XML,
> and JSON - so its a good start...
>
> however the list could end up being quite large, so I want to
> condition it by fields.
>
> Conceptually something like:
>
> logs.xml?source=&class=&method=& etc, allowing the caller to pass
> basic query parameters to the index action.
>
> I don't want to use $_GET though, I'd prefer to use something like
> named parameters, but unsure how to make this play nice.

For GET requests, have a look at $this->request->query.


>
> Do i need to set up custom ReST routing instead of mapResources() to
> achieve this?

You can use mapResources to make _fancy_ URLs, but if you want to pass
parameters to your index view like in the example above, you can just
refer to the default configuration.


Cheers,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: cakephp url rewriting and domain name with accents

2011-10-20 Thread Matteo Landi
On Thu, Oct 20, 2011 at 9:27 PM, whatsnew  wrote:
> Hi,
>
> Does anyone know if cakephp url rewriting handles properly domains
> names with accents?

Correct me if I'm wrong, but if you speak about URL rewrite you are
talking of the web-server and not of CakePHP; however I guess both
web-servers (e.g. Apache) and CakePHP should be able to handle such
domains flawlessly (supposed you can buy domains with accents).


My two cents,
Matteo

>
> I have a customer who wishes/needs a domain with an accent in it
> (something like vivelabière.com). I'm aware that's not good idea but
> that's not up to me.
>
> thanks for your insights.
>
> --
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Testing a RESTful controller

2011-10-20 Thread Matteo Landi
On Mon, Oct 17, 2011 at 11:58 PM, Matteo Landi  wrote:
> Hi everybody.
>
> I am looking for some advice on how to test RESTful controllers
> exchanging JSON data (I'm using $this->request->input() on all
> requests methods to fetch data coming from clients). Here is the test
> I started to write:
>
>  class UsersControllerTest extends ControllerTestCase {
>        public $fixtures = array('app.user');
>
>        public function testViewJson() {
>                $data = json_encode(array(
>                        'id' => 1
>                ));
>                $result = $this->testAction(
>                        '/users.json',
>                        array('data' => $data, 'method' => 'GET')
>                );
>                debug($result);
>        }
> }
>
> If I run the test, I'm getting the following error:
>
> Fatal error: Cannot unset string offsets in
> /home/matteo/workspace/partygoat/lib/Cake/Network/CakeRequest.php on
> line 183 Call Stack: 0.0003 351908 1. {main}()
> /home/matteo/workspace/partygoat/api/webroot/test.php:0 0.0132 1515196
> 2. CakeTestSuiteDispatcher::run()
> /home/matteo/workspace/partygoat/api/webroot/test.php:92 0.0132
> 1515764 3. CakeTestSuiteDispatcher->dispatch()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:114
> 0.0335 1670872 4. CakeTestSuiteDispatcher->_runTestCase()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:97
> 0.0361 1948588 5. CakeTestSuiteCommand->run()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:252
> 0.0635 5160212 6. CakeTestRunner->doRun()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteCommand.php:113
> 0.0934 8174532 7. PHPUnit_TextUI_TestRunner->doRun()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestRunner.php:58
> 0.0945 8304784 8. PHPUnit_Framework_TestSuite->run()
> /usr/share/php/PHPUnit/TextUI/TestRunner.php:305 0.1004 8960128 9.
> PHPUnit_Framework_TestSuite->runTest()
> /usr/share/php/PHPUnit/Framework/TestSuite.php:742 0.1004 8960128 10.
> CakeTestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:766
> 0.1245 8964536 11. PHPUnit_Framework_TestCase->run()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestCase.php:81
> 0.1247 8964536 12. PHPUnit_Framework_TestResult->run()
> /usr/share/php/PHPUnit/Framework/TestCase.php:575 0.2543 8978228 13.
> PHPUnit_Framework_TestCase->runBare()
> /usr/share/php/PHPUnit/Framework/TestResult.php:629 0.2580 9083636 14.
> PHPUnit_Framework_TestCase->runTest()
> /usr/share/php/PHPUnit/Framework/TestCase.php:627 0.2581 9084740 15.
> ReflectionMethod->invokeArgs()
> /usr/share/php/PHPUnit/Framework/TestCase.php:737 0.2581 9084768 16.
> UsersControllerTest->testViewJson()
> /home/matteo/workspace/partygoat/api/Test/Case/Controller/UsersControllerTest.php:0
> 0.2582 9085444 17. UsersControllerTest->testAction()
> /home/matteo/workspace/partygoat/api/Test/Case/Controller/UsersControllerTest.php:12
> 0.2582 9085772 18. ControllerTestCase->__call()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:0
> 0.2582 9086180 19. call_user_func_array()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:169
> 0.2582 9086496 20. ControllerTestCase->_testAction()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:0
> 0.2583 9093896 21. CakeRequest->__construct()
> /home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:207
> 0.2588 9094164 22. CakeRequest->_processGet()
> /home/matteo/workspace/partygoat/lib/Cake/Network/CakeRequest.php:136
>
> and if I comment the line raising the error (which tries unset
> '/users.json' from $query), even if the test goes on with no problems,
> inside the Controller $this->request->input() seems to be emtpy.
> Should I have to fill a bug request for this error?

My fault: it seems that the ``data`` parameter of the ``testAction``
should be an array and I was actually trying to pass a string.

At this point:
1 is it possible to test an action passing as data a plain string
instead of a key-valued one?
2 how is it possible to test PUT or DELETE actions?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Runnin tests on CakePHP 2.0

2011-10-20 Thread Matteo Landi
> One last question: while testing SQLite databases with cake, where are
> they supposed to be found? Each time I run `Console/cake testsuite app
> etc.' from the app directory, I always end up with an error (unable to
> connect to one of the tested tables); moreover two databases are
> created in the current directory, with names as set inside
> Config/database. On the other hand, from the browser everything works
> flawlessly. Have you got any hint about where to spot possible
> configuration errors?

For those of you interested in such a problem, I managed to solve it
by running the cake shell inside the app/webroot directory (assuming
your *test* SQLite database configuration contains a _relative_ path
the database file).


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: SQLite and database exceptions.

2011-10-20 Thread Matteo Landi
On Tue, Oct 18, 2011 at 7:07 PM, José Lorenzo  wrote:
> Use try-catch.
> Alternatively, override save() in AppModel and tor try { parent::save()}
> catch (Exception $e) { //do something }

For some reason I have not thought about that: thank you so much!


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Testing a RESTful controller

2011-10-17 Thread Matteo Landi
Hi everybody.

I am looking for some advice on how to test RESTful controllers
exchanging JSON data (I'm using $this->request->input() on all
requests methods to fetch data coming from clients). Here is the test
I started to write:

 1
));
$result = $this->testAction(
'/users.json',
array('data' => $data, 'method' => 'GET')
);
debug($result);
}
}

If I run the test, I'm getting the following error:

Fatal error: Cannot unset string offsets in
/home/matteo/workspace/partygoat/lib/Cake/Network/CakeRequest.php on
line 183 Call Stack: 0.0003 351908 1. {main}()
/home/matteo/workspace/partygoat/api/webroot/test.php:0 0.0132 1515196
2. CakeTestSuiteDispatcher::run()
/home/matteo/workspace/partygoat/api/webroot/test.php:92 0.0132
1515764 3. CakeTestSuiteDispatcher->dispatch()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:114
0.0335 1670872 4. CakeTestSuiteDispatcher->_runTestCase()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:97
0.0361 1948588 5. CakeTestSuiteCommand->run()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:252
0.0635 5160212 6. CakeTestRunner->doRun()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestSuiteCommand.php:113
0.0934 8174532 7. PHPUnit_TextUI_TestRunner->doRun()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestRunner.php:58
0.0945 8304784 8. PHPUnit_Framework_TestSuite->run()
/usr/share/php/PHPUnit/TextUI/TestRunner.php:305 0.1004 8960128 9.
PHPUnit_Framework_TestSuite->runTest()
/usr/share/php/PHPUnit/Framework/TestSuite.php:742 0.1004 8960128 10.
CakeTestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:766
0.1245 8964536 11. PHPUnit_Framework_TestCase->run()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/CakeTestCase.php:81
0.1247 8964536 12. PHPUnit_Framework_TestResult->run()
/usr/share/php/PHPUnit/Framework/TestCase.php:575 0.2543 8978228 13.
PHPUnit_Framework_TestCase->runBare()
/usr/share/php/PHPUnit/Framework/TestResult.php:629 0.2580 9083636 14.
PHPUnit_Framework_TestCase->runTest()
/usr/share/php/PHPUnit/Framework/TestCase.php:627 0.2581 9084740 15.
ReflectionMethod->invokeArgs()
/usr/share/php/PHPUnit/Framework/TestCase.php:737 0.2581 9084768 16.
UsersControllerTest->testViewJson()
/home/matteo/workspace/partygoat/api/Test/Case/Controller/UsersControllerTest.php:0
0.2582 9085444 17. UsersControllerTest->testAction()
/home/matteo/workspace/partygoat/api/Test/Case/Controller/UsersControllerTest.php:12
0.2582 9085772 18. ControllerTestCase->__call()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:0
0.2582 9086180 19. call_user_func_array()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:169
0.2582 9086496 20. ControllerTestCase->_testAction()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:0
0.2583 9093896 21. CakeRequest->__construct()
/home/matteo/workspace/partygoat/lib/Cake/TestSuite/ControllerTestCase.php:207
0.2588 9094164 22. CakeRequest->_processGet()
/home/matteo/workspace/partygoat/lib/Cake/Network/CakeRequest.php:136

and if I comment the line raising the error (which tries unset
'/users.json' from $query), even if the test goes on with no problems,
inside the Controller $this->request->input() seems to be emtpy.
Should I have to fill a bug request for this error?

Finally, inside ``testAction`` documentation it seems possible to set
data for GET and POST requests only: is this true? If so, how can I
prefil ``php://input`` with data enabling my RESTful controller to
run?


Thank you in advance,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Runnin tests on CakePHP 2.0

2011-10-17 Thread Matteo Landi
On Mon, Oct 17, 2011 at 12:48 AM, majna  wrote:
> try to uncomment this line
> https://github.com/cakephp/cakephp/blob/2.0/app/Config/core.php#L95
>
> or play with Configure::write('App.baseUrl', env('SCRIPT_NAME')); in
> test.php,
> I don't know...

I started to read TestSuite internals and find out that
$_SERVER['PHP_SELF'] was set to index.php instead of test.php; then I
checked cakephp-instaweb source code and noticed that there was a line
explicitly setting the 'SCRIPT_NAME' environment variable; without
that line, I was finally able to run tests from the browser: YAY!

One last question: while testing SQLite databases with cake, where are
they supposed to be found? Each time I run `Console/cake testsuite app
etc.' from the app directory, I always end up with an error (unable to
connect to one of the tested tables); moreover two databases are
created in the current directory, with names as set inside
Config/database. On the other hand, from the browser everything works
flawlessly. Have you got any hint about where to spot possible
configuration errors?


Regards,
Matteo

PS. for what is worth, I forked cakephp-instaweb and added support for
both cakephp2.0 and the testsuite; check it out:
https://github.com/iamFIREcracker/cakephp-instaweb

>
> Maybe you should open issue on "cakephp-instaweb" github.
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: $fields not honored inside hasMany relation

2011-10-17 Thread Matteo Landi
On Mon, Oct 17, 2011 at 6:44 AM, WebbedIT  wrote:
> You agree that the primary key of a table for which you are then
> fetching related hasMany records is required as part of Cakes
> automagic on hasMany associations.  It would then take more processing
> (albeit, a negligable amount) to then unset that primary key.

Well, I agree with you about what you said, but my question is about
not showing the foreign key of an associated Model
(Post->hasMany->Comment): such field is useful while _joining_ tables,
but once you have the data I don't get why it is still necessary.

>
> But the question I ask myself is, what problem does it cause you by
> existing in the results array?
>
> You are not forced to then use it in your view so just ignore it!

I know I can post-process returned data, but avoiding the db to return
useless data seems to me a more elegant and efficient solution;
moreover, given that the docs does not put any constraints on the
hasmany->fields variable, I'm curious to understand why that foreign
key is still necessary.

I don't know CakePHP internals but I imagine a query like this is used
to fetch associated data:

SELECT $fields specified in association fields
FROM comments
WHERE comments.post_id = $post_id

If this is true, imho there is no need to keep the foreign key there
(this is not true for the comment id (primary key), which must be
there not to break CakePHP Model engine.

Is there anything I'm not taking into account? If so, please correct me.


Cheers,
Matteo
>
> HTH, Paul
>
> On Oct 16, 11:42 am, Matteo Landi  wrote:
>> On Tue, Oct 11, 2011 at 6:23 PM, Matteo Landi  wrote:
>> > On Tue, Oct 11, 2011 at 6:15 AM, Angad Nadkarni
>> >  wrote:
>> >> Hi Matteo, this is not a bug. Cake requires the post_id field  to
>> >> fetch the associated Post associated array
>> >> as well, hence even when you don't mention it, the "PRIMARY" and
>> >> "FOREIGN" key fields are always mentioned.
>>
>> > I agree with you when you saying that to fetch all the comments
>> > associated to a given post the query engine need to work with
>> > ``post_id`` field, but what I quite don't understand is why such field
>> > is not removed after such comments are fethced; is the $field
>> > information used only before of the query? If so, are there any
>> > particular reasons behind that choice?
>>
>> The more I think of this, the less I understand why that field cannot
>> be removed by the engine itself.
>>
>> However, what is the more elegant way to remove those fields? Maybe
>> using ``finderQuery`` model field?
>>
>> Regards,
>> Matteo
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> > Regards,
>> > Matteo
>>
>> >> On Oct 10, 3:26 am, Matteo Landi  wrote:
>> >>> Hi everybody,
>> >>> I'm trying to create a simple cakephp application which handles posts
>> >>> and comments (like the one presented in the tutorial); I have a Post
>> >>> model which *hasMany* Comments, and I have a Comment which *belongsTo*
>> >>> to a Post.
>>
>> >>> I would like to use Post->hasMany['fields'] variable to reduce the set
>> >>> of fetched attributes, but for some strange reasons, I'm getting also
>> >>> attributes not present in the specified array; in particular, I get
>> >>> all the specified attributes plus the foreignKey (e.g. if my Comment
>> >>> is composed by an 'id', a 'body', a couple of date fields and
>> >>> 'post_id' (our foreignKey), and if I set *fields* to array('id'), I
>> >>> get back both 'id' and 'post_id' attributes).
>>
>> >>> However, while I fetch the Post associated to a Comment, the list of
>> >>> fetched attributes seems to match the one specified in the association
>> >>> definition.
>>
>> >>> Is this a bug, or is there anything I'm not taking into account?
>>
>> >>> Regards,
>> >>> Matteo
>>
>> >>> --http://www.matteolandi.net/
>>
>> >> --
>> >> Our newest site for the community: CakePHP Video 
>> >> Tutorialshttp://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+unsub

Re: Runnin tests on CakePHP 2.0

2011-10-16 Thread Matteo Landi
On Mon, Oct 17, 2011 at 12:10 AM, majna  wrote:
> I think your web server is hardcoded to rewrite only index.php.
> https://github.com/lamby/cakephp-instaweb/blob/master/cakephp_instaweb.py
>
> try suggested apps above :(

I think you are wrong: I'm able to load the summary page of the tests
(http://localhost:3000/test.php), but all the links seem to be broken
because they point to index.php instead of test.php (have a look at
the source of the rendered page http://pastebin.com/estRQL5V).

If I copy one of those links in the browser address bar and replace
index.php with test.php, I am able to run the selected test with no
problems: for this reason I guess there is something wrong with the
tests template page, or even worse with my cakephp installation (3
days old github checkout).


Regards,
Matteo

>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Runnin tests on CakePHP 2.0

2011-10-16 Thread Matteo Landi
On Sun, Oct 16, 2011 at 3:47 PM, majna  wrote:
> maybe there's issues with your python web server,
> try using wamp, mamp, xampp etc. for your stack
>
> Check PHPunit install and required version from CLI first.

You saved my day: when I installed PHPUnit with apt, didn't notice
that even if the installation was fine the application was exiting
with a 255 error. So I find out I had some deps missing; now the cli
interface seems to work perfectly.

For what concerns the web ui I'm now able to read the summary page,
but links seem to be broken because they start with index.php instead
of test.php: is there anything wrong with my installation?


Regards,
Matteo

>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: $fields not honored inside hasMany relation

2011-10-16 Thread Matteo Landi
On Tue, Oct 11, 2011 at 6:23 PM, Matteo Landi  wrote:
> On Tue, Oct 11, 2011 at 6:15 AM, Angad Nadkarni
>  wrote:
>> Hi Matteo, this is not a bug. Cake requires the post_id field  to
>> fetch the associated Post associated array
>> as well, hence even when you don't mention it, the "PRIMARY" and
>> "FOREIGN" key fields are always mentioned.
>
> I agree with you when you saying that to fetch all the comments
> associated to a given post the query engine need to work with
> ``post_id`` field, but what I quite don't understand is why such field
> is not removed after such comments are fethced; is the $field
> information used only before of the query? If so, are there any
> particular reasons behind that choice?

The more I think of this, the less I understand why that field cannot
be removed by the engine itself.

However, what is the more elegant way to remove those fields? Maybe
using ``finderQuery`` model field?


Regards,
Matteo

>
>
> Regards,
> Matteo
>
>> On Oct 10, 3:26 am, Matteo Landi  wrote:
>>> Hi everybody,
>>> I'm trying to create a simple cakephp application which handles posts
>>> and comments (like the one presented in the tutorial); I have a Post
>>> model which *hasMany* Comments, and I have a Comment which *belongsTo*
>>> to a Post.
>>>
>>> I would like to use Post->hasMany['fields'] variable to reduce the set
>>> of fetched attributes, but for some strange reasons, I'm getting also
>>> attributes not present in the specified array; in particular, I get
>>> all the specified attributes plus the foreignKey (e.g. if my Comment
>>> is composed by an 'id', a 'body', a couple of date fields and
>>> 'post_id' (our foreignKey), and if I set *fields* to array('id'), I
>>> get back both 'id' and 'post_id' attributes).
>>>
>>> However, while I fetch the Post associated to a Comment, the list of
>>> fetched attributes seems to match the one specified in the association
>>> definition.
>>>
>>> Is this a bug, or is there anything I'm not taking into account?
>>>
>>> Regards,
>>> Matteo
>>>
>>> --http://www.matteolandi.net/
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials 
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
>> http://groups.google.com/group/cake-php
>>
>
>
>
> --
> http://www.matteolandi.net/
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


SQLite and database exceptions.

2011-10-16 Thread Matteo Landi
Hi everybody,

I'm developing a test application on top of a SQLite database. As you
probably may know, by default *integrity checks* on SQLite database
are disabled, and in order to activate them you need to issue the
following query once the connection with the database has been
enstablished:

PRAGMA foreign_keys = ON;

So I implemented a ``beforeSave`` for my models and execute a query
with that string (I know executing it more than once, but for the
moment that inefficiency does not represent a problem). Everything
works as expected: integrity across db tables is now always
guaranteed.

I'm here because I would like to know if it is possible to force
cakephp not to raise 500 error for database errors; if I add a comment
to a nonexistent post I get a 500 error instead of a *failing*
Model->save(), hence the only thing I have to do is to put the call to
Model->save() inside a try/catch block. Are there any alternatives to
this?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Runnin tests on CakePHP 2.0

2011-10-16 Thread Matteo Landi
Hi everybody,

I'm having some troubles trying to run tests (both browser and cli):
on the one hand if I open http://localhost:3000/test.php (I'm using
cakephp-instaweb) I get a blank page and I am unable to select tests
to run; on the other, if I run ./Console/cake testsuite core
Core/ConsoleOutput (as explained here
http://book.cakephp.org/2.0/en/development/testing.html#filtering-test-cases)
nothing seems to happen. Am I doing something wrong?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: $fields not honored inside hasMany relation

2011-10-11 Thread Matteo Landi
On Tue, Oct 11, 2011 at 6:15 AM, Angad Nadkarni
 wrote:
> Hi Matteo, this is not a bug. Cake requires the post_id field  to
> fetch the associated Post associated array
> as well, hence even when you don't mention it, the "PRIMARY" and
> "FOREIGN" key fields are always mentioned.

I agree with you when you saying that to fetch all the comments
associated to a given post the query engine need to work with
``post_id`` field, but what I quite don't understand is why such field
is not removed after such comments are fethced; is the $field
information used only before of the query? If so, are there any
particular reasons behind that choice?


Regards,
Matteo

> On Oct 10, 3:26 am, Matteo Landi  wrote:
>> Hi everybody,
>> I'm trying to create a simple cakephp application which handles posts
>> and comments (like the one presented in the tutorial); I have a Post
>> model which *hasMany* Comments, and I have a Comment which *belongsTo*
>> to a Post.
>>
>> I would like to use Post->hasMany['fields'] variable to reduce the set
>> of fetched attributes, but for some strange reasons, I'm getting also
>> attributes not present in the specified array; in particular, I get
>> all the specified attributes plus the foreignKey (e.g. if my Comment
>> is composed by an 'id', a 'body', a couple of date fields and
>> 'post_id' (our foreignKey), and if I set *fields* to array('id'), I
>> get back both 'id' and 'post_id' attributes).
>>
>> However, while I fetch the Post associated to a Comment, the list of
>> fetched attributes seems to match the one specified in the association
>> definition.
>>
>> Is this a bug, or is there anything I'm not taking into account?
>>
>> Regards,
>> Matteo
>>
>> --http://www.matteolandi.net/
>
> --
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Approve data changes

2011-10-11 Thread Matteo Landi
I suggest you to store different versions of user information using a
``revision`` column; this way you could show the user the last
_accepted_ version, while the admin is able to accept the last
_modified_ one.


Cheers,
Matteo

On Tue, Oct 11, 2011 at 7:25 AM, nOLL  wrote:
> Hi,
>
> There is situation that user update their profile. But, users cannot
> view the changes until admin approve it.  Is it i need to use
> temporary table for data update by user? Or any other idea to
> implement this?
>
> Thanks.
> nOLL
>
> --
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php
>



-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


$fields not honored inside hasMany relation

2011-10-10 Thread Matteo Landi
Hi everybody,
I'm trying to create a simple cakephp application which handles posts
and comments (like the one presented in the tutorial); I have a Post
model which *hasMany* Comments, and I have a Comment which *belongsTo*
to a Post.

I would like to use Post->hasMany['fields'] variable to reduce the set
of fetched attributes, but for some strange reasons, I'm getting also
attributes not present in the specified array; in particular, I get
all the specified attributes plus the foreignKey (e.g. if my Comment
is composed by an 'id', a 'body', a couple of date fields and
'post_id' (our foreignKey), and if I set *fields* to array('id'), I
get back both 'id' and 'post_id' attributes).

However, while I fetch the Post associated to a Comment, the list of
fetched attributes seems to match the one specified in the association
definition.

Is this a bug, or is there anything I'm not taking into account?


Regards,
Matteo

-- 
http://www.matteolandi.net/

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


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Validation errors

2010-05-22 Thread Matteo
Hi,

you could try this:

http://cakeqs.org/eng/questions/view/validation_summary

there are many posts about validation under cakephp questions, I would
check there too if you already didn't.

Then lastly I would try changing model name and check if validation
behaves correctly.

Hope it helps.

Matteo

On May 22, 10:22 am, Ed Propsner  wrote:
> @Master Ram
>
> I appreciate the advice but doesn't this seem a bit long winded for
> something that normally requires no code at all besides the validation rules
> in the model?
>
>  if ($form->isFieldError('Model_name.Field_name')){
>
>             e($form->error('Model_name.Field_name',
>                             null,
>                             array(
>                             'class' => 'failure')
>                           ));
>         }
>
> What if you have a form with say 20 fields that need to be validated?
>
> There is reason the validation errors are not outputting to the page,
> instead of a work around I'd be more interested in finding the cause to the
> problem.
>
> @Matteo,
>
> Thanks, I looked it over but nothing seemed to apply.
>
>
>
>
>
> On Sat, May 22, 2010 at 4:04 AM, Matteo  wrote:
> > Hi,
>
> > you can check my post here and see if it - maybe - fits your needs.
> > Please, see last reply.
>
> >http://groups.google.com/group/cake-php/browse_thread/thread/2f6a264d...
>
> > Matteo
>
> > On May 22, 8:50 am, Ed Propsner  wrote:
> > > I have a form that is not displaying validation errors like it should be.
> > > The errors are there in the validationErrors array so the model is
> > > validating, I'm sure of that.
> > > I've been reading through a few other threads on the same subject but
> > none
> > > of the causes seem to apply.
>
> > > I have the controller and the model stripped down to next to nothing.
>
> > > [controller]
>
> > > function add()
> > > {
> > > if(!empty($this->data))
> > > {
> > > $this->data['ProfileAttrib']['user_id'] = $this->Auth->User('id');
> > > $this->ProfileAttrib->save($this->data);
>
> > > }
> > > }
>
> > > [/controller]
>
> > > Then in the model I validate field 'gender'
>
> > > [model]
>
> > > class ProfileAttrib extends AppModel
> > >  {
>
> > > var $name = 'ProfileAttrib';
>
> > >  var $validate = array(
> > >       'gender' => array(
> > > 'rule' => 'notEmpty',
> > > 'message' => 'Message here'
> > > )
> > >      );
>
> > > }
>
> > > [/model]
>
> > > I also stripped down the view to just a form and a single field for
> > gender.
> > > Whatever the reason is that validation messages aren't displaying I'm
> > really
> > > not seeing it.
> > > I can't strip things down any more than what they are now.
>
> > > Any advice?
>
> > > - Ed
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others
> > with their CakePHP related questions.
>
> > > 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 > >  om>For more options, visit this group athttp://
> > groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > 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 > om>For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> 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 For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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 For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Validation errors

2010-05-22 Thread Matteo
Hi,

you can check my post here and see if it - maybe - fits your needs.
Please, see last reply.

http://groups.google.com/group/cake-php/browse_thread/thread/2f6a264df0492006

Matteo

On May 22, 8:50 am, Ed Propsner  wrote:
> I have a form that is not displaying validation errors like it should be.
> The errors are there in the validationErrors array so the model is
> validating, I'm sure of that.
> I've been reading through a few other threads on the same subject but none
> of the causes seem to apply.
>
> I have the controller and the model stripped down to next to nothing.
>
> [controller]
>
> function add()
> {
> if(!empty($this->data))
> {
> $this->data['ProfileAttrib']['user_id'] = $this->Auth->User('id');
> $this->ProfileAttrib->save($this->data);
>
> }
> }
>
> [/controller]
>
> Then in the model I validate field 'gender'
>
> [model]
>
> class ProfileAttrib extends AppModel
>  {
>
> var $name = 'ProfileAttrib';
>
>  var $validate = array(
>       'gender' => array(
> 'rule' => 'notEmpty',
> 'message' => 'Message here'
> )
>      );
>
> }
>
> [/model]
>
> I also stripped down the view to just a form and a single field for gender.
> Whatever the reason is that validation messages aren't displaying I'm really
> not seeing it.
> I can't strip things down any more than what they are now.
>
> Any advice?
>
> - Ed
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> 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 For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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 For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: No validation after deploy

2010-05-22 Thread Matteo
Hi all,

solved. I'm posting that hoping it could be of some help.

The cause was the name of my model file. I used 'Latest.php' instead
of 'latest.php'. Because of the first capital letter, in the host
server validation didn't work.

My machine and the which one of the remote server are BOTH .nix
machines.

BUT pay attention if, like my case, you develop on a Mac with Mac Os
Extended Journaled filesystem that's different from the Extended
journaled (Case-sensitive) one!!

Thanx

Matteo

On May 21, 10:28 am, Matteo  wrote:
> thanx Nicolas, however the PHP version is the 5.2.x in both
> environments.
>
> On May 21, 9:31 am, "Nicolas Maleve"  wrote:
>
>
>
>
>
> > I had a similar problem once with a validation rule.
> > It was due to the difference of PHP versions between my dev environment
> > (php5) and the production environment (php4)
> > Upgrading the production environment to php5 was the solution, but it
> > isn't always possible.
>
> > ,n
> > Le Ven 21 mai 2010 9:08, Matteo a écrit :
>
> > > Hi Andrei,
>
> > > the "model" one, please see below:
>
> > > class Latest extends AppModel
> > > {
> > >             var $name = 'Latest';
>
> > >             var $validate = array(
> > >                   'title' =>  array('rule' => 'notEmpty', 'message' =>
> > > 'mandatory field'),
> > >                   'body' =>  array('rule' => 'notEmpty', 'message' =>
> > > 'mandatory field')
> > >             );
> > > }
>
> > > How is it possible it works on my Mac and not online??
>
> > > Thank you
>
> > > Matteo
>
> > > On May 21, 8:48 am, Andrei Mita  wrote:
> > >> Do you use model validation or a custom made one?
>
> > >> On Thu, May 20, 2010 at 9:58 PM, Matteo  wrote:
> > >> > Hi all,
>
> > >> > hope you can help a very newbe one.
>
> > >> > I have a very simple form with two fields: title and body.
>
> > >> > In my dev enviroment I check for the two fields to be fill.
> > >> > Validation works fine, if the fields are left blank, it shows the
> > >> > message error.
>
> > >> > The problem is with deploy. In my deploy env. (dreamhost) if I leave
> > >> > the fields blank it submits the same!!
>
> > >> > Have you ever experienced anything similar??
>
> > >> > Can't find a solution.
>
> > >> > A case similar to that can be due to .htaccess configuration?
>
> > >> > I can't think at any other couses!!
>
> > >> > Working with 1.2.7 V.
>
> > >> > Thanx a lot
>
> > >> > Matteo
>
> > >> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> > >> others
> > >> > with their CakePHP related questions.
>
> > >> > 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 > >> om>For more options, visit this group at
> > >> >http://groups.google.com/group/cake-php?hl=en
>
> > >> Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers
> > >> with their CakePHP related questions.
>
> > >> 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 For more options, visit this group
> > >> athttp://groups.google.com/group/cake-php?hl=en
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others
> > > with their CakePHP related questions.
>
> > > 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 For more options, visit this group
> > > athttp://groups.google.com/group/cake-php?hl=

Re: No validation after deploy

2010-05-21 Thread Matteo
thanx Nicolas, however the PHP version is the 5.2.x in both
environments.


On May 21, 9:31 am, "Nicolas Maleve"  wrote:
> I had a similar problem once with a validation rule.
> It was due to the difference of PHP versions between my dev environment
> (php5) and the production environment (php4)
> Upgrading the production environment to php5 was the solution, but it
> isn't always possible.
>
> ,n
> Le Ven 21 mai 2010 9:08, Matteo a écrit :
>
>
>
> > Hi Andrei,
>
> > the "model" one, please see below:
>
> > class Latest extends AppModel
> > {
> >             var $name = 'Latest';
>
> >             var $validate = array(
> >                   'title' =>  array('rule' => 'notEmpty', 'message' =>
> > 'mandatory field'),
> >                   'body' =>  array('rule' => 'notEmpty', 'message' =>
> > 'mandatory field')
> >             );
> > }
>
> > How is it possible it works on my Mac and not online??
>
> > Thank you
>
> > Matteo
>
> > On May 21, 8:48 am, Andrei Mita  wrote:
> >> Do you use model validation or a custom made one?
>
> >> On Thu, May 20, 2010 at 9:58 PM, Matteo  wrote:
> >> > Hi all,
>
> >> > hope you can help a very newbe one.
>
> >> > I have a very simple form with two fields: title and body.
>
> >> > In my dev enviroment I check for the two fields to be fill.
> >> > Validation works fine, if the fields are left blank, it shows the
> >> > message error.
>
> >> > The problem is with deploy. In my deploy env. (dreamhost) if I leave
> >> > the fields blank it submits the same!!
>
> >> > Have you ever experienced anything similar??
>
> >> > Can't find a solution.
>
> >> > A case similar to that can be due to .htaccess configuration?
>
> >> > I can't think at any other couses!!
>
> >> > Working with 1.2.7 V.
>
> >> > Thanx a lot
>
> >> > Matteo
>
> >> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> >> others
> >> > with their CakePHP related questions.
>
> >> > 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 >> om>For more options, visit this group at
> >> >http://groups.google.com/group/cake-php?hl=en
>
> >> Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others
> >> with their CakePHP related questions.
>
> >> 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 For more options, visit this group
> >> athttp://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > 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 For more options, visit this group
> > athttp://groups.google.com/group/cake-php?hl=en
>
>          *
>     *
>   *
>   *
>    *
>      *
>        *
>           *
>               *
>                   C O N S T A N T
>                        V Z W
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> 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 For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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 For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: No validation after deploy

2010-05-21 Thread Matteo
Hi Andrei,

the "model" one, please see below:

class Latest extends AppModel
{
var $name = 'Latest';

var $validate = array(
  'title' =>  array('rule' => 'notEmpty', 'message' =>
'mandatory field'),
  'body' =>  array('rule' => 'notEmpty', 'message' =>
'mandatory field')
);
}

How is it possible it works on my Mac and not online??

Thank you

Matteo

On May 21, 8:48 am, Andrei Mita  wrote:
> Do you use model validation or a custom made one?
>
>
>
>
>
> On Thu, May 20, 2010 at 9:58 PM, Matteo  wrote:
> > Hi all,
>
> > hope you can help a very newbe one.
>
> > I have a very simple form with two fields: title and body.
>
> > In my dev enviroment I check for the two fields to be fill.
> > Validation works fine, if the fields are left blank, it shows the
> > message error.
>
> > The problem is with deploy. In my deploy env. (dreamhost) if I leave
> > the fields blank it submits the same!!
>
> > Have you ever experienced anything similar??
>
> > Can't find a solution.
>
> > A case similar to that can be due to .htaccess configuration?
>
> > I can't think at any other couses!!
>
> > Working with 1.2.7 V.
>
> > Thanx a lot
>
> > Matteo
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > 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 > om>For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> 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 For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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 For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


No validation after deploy

2010-05-20 Thread Matteo
Hi all,

hope you can help a very newbe one.

I have a very simple form with two fields: title and body.

In my dev enviroment I check for the two fields to be fill.
Validation works fine, if the fields are left blank, it shows the
message error.

The problem is with deploy. In my deploy env. (dreamhost) if I leave
the fields blank it submits the same!!

Have you ever experienced anything similar??

Can't find a solution.

A case similar to that can be due to .htaccess configuration?

I can't think at any other couses!!

Working with 1.2.7 V.

Thanx a lot

Matteo

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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 For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en