-- j5 <[EMAIL PROTECTED]> wrote
(on Wednesday, 10 December 2008, 05:50 PM -0800):
>
> Model Definition
> <?
> require_once dirname(__FILE__) . '/Model.php';
>
> Class My_User extends My_Model
> {
>
>
> ...
>
> } // end class
>
> Form Definition
>
> class My_Form_StandardLogin extends Zend_Form
> {
> protected $_userModel = null;
>
> public function __construct($config=array())
> {
> if (is_array($config) && array_key_exists('model', $config)) {
> $this->_model = $config['model'];
Here's the problem -- you define a protected $_userModel member, but
then you're setting a non-existent $_model member -- which will have
public visibility. Change the above to $this->_userModel.
> }
> parent::__construct($config);
> }
>
> public function init()
> {
> $this->addElementPrefixPath('My_Validate', APPLICATION_PATH .
> '/models/Validate/', 'validate');
>
> $email = $this->addElement('text', 'email', array(
> 'filters' => array('StringTrim'),
> 'validators' => array(
> array('EmailAddress', true),
> array('EmailExists', true, array($this->_userModel)),
> ),
> 'required' => true,
> 'label' => 'Email address:',
> 'size' => 50,
> 'maxlength' => 75,
> ));
>
> ...
> } // end class
>
> Then in the controller
>
> $form = $this->_helper->getForm(
> 'StandardLogin',
> array(
> 'method' => 'post',
> 'action' => '/login',
> 'model' => $this->_userModel
> )
> );
>
>
>
> And then in the view
>
> <?= $this->loginForm ?>
>
>
> I am using the latest ZF 1.7.1
>
>
>
> Matthew Weier O'Phinney-3 wrote:
> >
> > -- j5 <> wrote
> > (on Wednesday, 10 December 2008, 05:22 PM -0800):
> >> hmm, I changed the member to protected but this still seems to trigger
> >> the
> >> warning error.
> >
> > Code? I've done this before without issues, so I'll need some code that
> > reproduces it to diagnose.
> >
> >
> >> Matthew Weier O'Phinney-3 wrote:
> >> >
> >> > -- j5 <> wrote
> >> > (on Wednesday, 10 December 2008, 02:42 PM -0800):
> >> >> For my login form, I pass the form my user model (to be used by
> >> >> validators)
> >> >> and in the forms init() I add the model to a private variable.
> >> >>
> >> >> I notice when I try display the form I get the following error.
> >> >> Warning: htmlspecialchars() expects parameter 1 to be string, object
> >> >> given
> >> >> in /home/blah/library/Zend/View/Abstract.php
> >> >>
> >> >> I tracked this problem back to my user model not having a __toString()
> >> >> function. If I add a __toString() function that returns '' within my
> >> user
> >> >> model this error goes away.
> >> >
> >> > Make the property storing the model protected. Public members are
> >> passed
> >> > as attributes to the view helper -- which is why you are getting this
> >> > message.
> >> >
> >> >> Does anyone have any ideas how to avoid this problem without having to
> >> >> create the __toString() soley for this purpose?
> >
> > --
> > Matthew Weier O'Phinney
> > Software Architect | [EMAIL PROTECTED]
> > Zend Framework | http://framework.zend.com/
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Attaching-a-model-within-a-Zend_Form-instance-causes-an-error-on-display-tp20945740p20948021.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/