Re: Uploaded Form Helper: FormationHelper
Wow, that is awesome. Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
RE: Uploaded Form Helper: FormationHelper
> [mailto:[EMAIL PROTECTED] On Behalf Of brandags > Wait - but don't I still need to send the validation rules, > etc. to the > view? Can you change what parameters are sent to the > startup() function? Well, here is your init function: function init($validations=null, $data=null) { $formData = array('validations' => $validations, 'data'=>$data); $this->controller->set('formData', $formData); } And you are calling it like this: function beforeFilter() { $this->Myform->controller = &$this; $this->Myform->init($this->User->validate, $this->data); } So you should be able to do this: // seemed to work with preliminary testing... function startup( &$controller ) { $validations = array() ; foreach( $controller->modelNames as $model ) { $validations += $controller->$model->validate ; } $this->controller = $controller ; $this->controller->set( 'formData', array( 'validations' => $validations, 'data' => $this->controller->data ) ) ; } -- Regards, Ryan Ginstrom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
Wait - but don't I still need to send the validation rules, etc. to the view? Can you change what parameters are sent to the startup() function? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
Oh, that's very nice! I was wondering if there was something like that. Thanks for letting me know. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
RE: Uploaded Form Helper: FormationHelper
> [mailto:[EMAIL PROTECTED] On Behalf Of brandags > It extends Cake's Form helper and also takes the validation from the > model (using the advanced validation method - multiple rules > per field) > so you don't have to retype the validation messages or which > fields are > required, in your view. I like the idea of getting validation errors from the model. One thing I noticed with your component code is the init() -- Components have a startup method that is called automatically with the controller as the param: (From the wiki) function startup(&$controller) { // This method takes a reference to the controller which is loading it. // Perform controller initialization here. } So you don't need to call anything in your beforeFilter; you can just put your initialization code here. -- Regards, Ryan Ginstrom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
I've also been working on a similar form helper. I just uploaded it at: http://cakeforge.org/snippet/detail.php?type=snippet&id=75 It extends Cake's Form helper and also takes the validation from the model (using the advanced validation method - multiple rules per field) so you don't have to retype the validation messages or which fields are required, in your view. It's still a work in progress and requires a few other components (the advanced validator, and error helper), but maybe we can learn from each other and get a really good form helper out there. I'm all for as little typing as possible! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
RE: Uploaded Form Helper: FormationHelper
> [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft > I repeat, use $value=$this->Html->tagValue($fieldName) for maximum > compatibility Thanks for the pointer. I actually ended up copying the HtmlHelper code into FormationHelper and modifying it, because tagValue was calling h() (AKA htmlspecialchars() ) on the value, which escapes HTML entities. Since I am using my database to store HTML text, that's not what I wanted. But the latest version of my posted code supports both $this->params['data'] and $this->data. Regards, Ryan --- Ryan Ginstrom [EMAIL PROTECTED] / [EMAIL PROTECTED] http://ginstrom.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
be careful, you're only using $this->data at helper, but it only works if you put $this->data in controller. There's two ways at controller to set the data, $this->data or $this->params['data']. You must check these two at your helper for ensure compatibility to all the users (if this is what you want). I repeat, use $value=$this->Html->tagValue($fieldName) for maximum compatibility --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
RE: Uploaded Form Helper: FormationHelper
> [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft > You don't need to pass $data to the helpers: see the blog > tutorial edit > action: OK, I have been enlightened. Thanks! Thanks to you, I've improved my component and cleaned up my controllers as well. Open source at its best. So the example code now stands at: beginForm( $html->url('/posts/add') ) ; ?> Edit Post hidden( 'Post/id' ) ; ?> inputLabel( 'Post/title', true ) ; ?> richLabel( 'Post/body', true ) ; ?> endForm() ; ?> // === Would still like a way to edit the descriptions, though... -- Regards, Ryan Ginstrom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
You don't need to pass $data to the helpers: see the blog tutorial edit action: function edit($id = null) { if (empty($this->data)) { $this->Post->id = $id; $this->data = $this->Post->read(); } else { if ($this->Post->save($this->data['Post'])) { $this->flash('Your post has been updated.','/posts'); } } } You always have $this->data at controller, then in your helper (including the html helper) you can do $value=$this->Html->tagValue($fieldname) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
RE: Uploaded Form Helper: FormationHelper
> [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft > If you use $this->params['data']=$data at your controller, then in the > helper is accessible through $this->params['data'] > > If you use $this->data at your controller, then in the helper > $this->data I've been doing: $this->set( 'data', $this->Post->findById( $id ) ) ; That's the way it is in the Blog tutorial: http://manual.cakephp.org/chapter/18 At any rate, I changed the helper so that you only need to pass in $data in the call to $formation->beginForm() ; That seems like a fairly painless middle ground, don't you think? So the revised example is: beginForm( "/speakers/edit/{$data['Speaker']['id']}", $data ) ; ?> Edit Speaker hidden( 'Speaker/id' ) ; ?> inputLabel( 'Speaker/name', true ) ; ?> habtmLabel( 'Presentation', $presentations, false ) ; ?> inputLabel( 'Speaker/email1', true ) ; ?> inputLabel( 'Speaker/email2', false ) ; ?> inputLabel( 'Speaker/url', false ) ; ?> richLabel( 'Speaker/bio', false ) ; ?> endForm() ; ?> / == -- Regards, Ryan Ginstrom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
Ok now I'm documented. If you use $this->params['data']=$data at your controller, then in the helper is accessible through $this->params['data'] If you use $this->data at your controller, then in the helper $this->data The correct way is to check where is the data. From HtmlHelper: function tagValue($fieldName) { $this->setFormTag($fieldName); if (isset($this->params['data'][$this->model][$this->field])) { return h($this->params['data'][$this->model][$this->field]); } elseif(isset($this->data[$this->model][$this->field])) { return h($this->data[$this->model][$this->field]); } return false; } You can use HtmlHelper in your own helper, and doing $value=$this->Html->tagValue($fieldName) you will get the correct value --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
mmm..but I think that $this->params['data']=$data; is "standard", see first blog tutorial of wiki, edit() action: http://wiki.cakephp.org/tutorials:blog_tutorial_-_1?s=params+data function edit($id=null) { if (empty($this->params['data'])) { $this->Post->id = $id; $this->params['data'] = $this->Post->read(); $this->render(); } else { if ( $this->Post->save($this->params['data']['Post'])) { $this->flash('Your post has been updated.','/posts'); } } } In newer versions of cake, $this->data at controller is used instead, I think that $this->data doesn't work in this case --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
I think that you must do $this->set('data',$data) at controller (it's standard) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
RE: Uploaded Form Helper: FormationHelper
> [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft > Looks promising, Thanks! > I think that you can avoid $data parameter, it must be accessible in > the helper through $this->params['data'] > (because HtmlHelper needs it) That's a good idea, and would definitely clean up the function calls. But it seems that in order to make the data available in the params, I'd have to explicitly set $this->params['data'] = $data ; in the controller. If I don't do that, all params gives me is the controller name, action name, url, etc. And that would harm the simplicity of use as a drop-in module, don't you think? Or is there another way? -- Regards, Ryan Ginstrom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Uploaded Form Helper: FormationHelper
Looks promising, I think that you can avoid $data parameter, it must be accessible in the helper through $this->params['data'] (because HtmlHelper needs it) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---