Validation redundancy. When save is called, the data passed to it in
the first parameter is validated using CakePHP validation mechanism.
Read more on Models -> Saving your data.

Also, the validation errors are already available to the view so no
need to set them. Try bake and see what it does to get a better feel
of the cake way.

Gary

On Fri, Aug 3, 2012 at 1:43 PM, MetZ <met...@gmail.com> wrote:
> Hi Mark..
>
> - Setting validation errors to view to display them in an element => You
> need to correct: Error message 1, Error message 2, Error message 3 => Need
> it ;)
> - __('some text', true) => For translation strings, not sure why I started
> to use the TRUE, but I think it is because of not beeing able to only have
> __('some text') inside the strings (Suggestion??)
>
> And for the validation Redundancy ? what exactly do you mean?
> I am validating in models => and pushing messages to the view (not using the
> error => true on my form fields, all are set to false and display the
> validation messages in element as explained before.
>
> And regarding baking.. Have never used it..  =) Any good tutorials on it? I
> need to use terminal right?
>
> I am developing on my development VPS server, not local, but have terminal
> access..
>
> Thanks for your time!
> -Tom
>
>
> kl. 20:05:19 UTC+2 fredag 3. august 2012 skrev euromark følgende:
>>
>> for starters, take out the validation redundancy
>> why setting the errors to the view? also not necessary
>> also, in 2.x your __() looks differently (arguments usually are not "true"
>> but replacement strings)
>>
>> why dont you use baking? it would display a better output than you
>> currently have
>>
>>
>>
>> Am Freitag, 3. August 2012 17:43:52 UTC+2 schrieb MetZ:
>>>
>>> Yes, I understand what you are doing :)
>>> Have a couple of those myself..
>>>
>>> But my question is (perhaps not clear enough), the best practice for a
>>> function like add and edit.
>>>
>>> I am thinking about:
>>> if ($this->request->is('post')) {
>>> $this->User->set($this->request->data);
>>> if ($this->User->validates()) {
>>> ++++
>>>
>>> Those things inside the function. Like,, what approach/setup would you
>>> use on cake 2.x to talk with the db and make things happen :)
>>>
>>> I am just wondering if I am doing it 100% correct, as I can not find any
>>> good tutorials on it anywhere..
>>>
>>> Here is my add function as is today, any pointers?
>>>
>>> public function admin_add() {
>>> $this->set('title_for_layout', __('Add new role',true));
>>> if ($this->request->is('post')) {
>>> $this->Role->set($this->request->data);
>>> if ($this->Role->validates()) {
>>>     if ($this->Role->save($this->request->data)) {
>>> $this->Session->setFlash(__('New role created.',true),
>>> 'admin/flash/success');
>>>                 $this->redirect(array('action' => 'index'));
>>> } else {
>>> $this->Session->setFlash(__('Could not create role, please try
>>> again.',true), 'admin/flash/error');
>>> }
>>> } else {
>>> // Didn't validate
>>> }
>>> }
>>> $this->set('errors', $this->Role->validationErrors);
>>> }
>>>
>>> -Tom
>>>
>>>
>>>
>>> kl. 13:35:30 UTC+2 fredag 3. august 2012 skrev SoulRaven følgende:
>>>>
>>>> i use a single method, add/edit even if is user or admin, the difference
>>>> between add/edit is that on edit you have the ID set, or in parameter or in
>>>> $this->data
>>>>
>>>> admin_editpost($id = null){
>>>>        if(is_null($id){
>>>>            //something
>>>>        }
>>>> }
>>>>
>>>> i guess you understand
>>>>
>>>> vineri, 3 august 2012, 11:41:01 UTC+3, MetZ a scris:
>>>>>
>>>>> Hi all..
>>>>>
>>>>> I am in the process of migrate one of my apps fra 1.3 to cakephp 2.x
>>>>> and I am wondering, what are the best practices for the new framework?
>>>>> AND YES, I have read the documents/book :)
>>>>>
>>>>> I am just wondering how you do it, so I can compare my work and see if
>>>>> I am heading in the right direction with my app.
>>>>>
>>>>> So if anyone could give me an idea about a couple simple add/edit
>>>>> functions, and how the best practice for this, I would appreciate it :)
>>>>>
>>>>> like:
>>>>>
>>>>> admin_users_add() {
>>>>> }
>>>>>
>>>>> admin_users_edit() {
>>>>> }
>>>>>
>>>>> and other regular functions you might have an example for.
>>>>>
>>>>> Thanks all!
>>>>> Awesome!
>>>>>
>>>>> -Tom
>
> --
> 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

Reply via email to