some simple questions

View: New views
4 Messages — Rating Filter:   Alert me  

some simple questions

by Neriodavid(Wei Dai) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
   Does anyone read the Cal Evans book, php|a's Guide to Programming with Zend Framework?
  
   I have some simple questions just want to make clear:

   If a class has a protected member/property, say _data, which be assigned to as a Zend' Db row object on the member table, can you access it as:

  after $this->_data = $member;
  $this->emailAddress, instead of $this->_data->emailAddress ?

  If you read the book, check out the chapter4's sample code, suddenly, we can directly access the $member->emailAdress?


  And, also, in the register view, when we assigned the view variable emailAddress etc, so use the echo $this->escape($this->emailAddress) do not generate an undefined variable warning?

These may stupid simple question, but these kind thing I never do. I check the code, does somewhere in the ZF has utilized the magic method, such as __get or __set to automatically handle this?

Thanks.

Re: some simple questions

by Bill Karwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Neriodavid(Wei Dai) wrote:
   If a class has a protected member/property, say _data, which be assigned
to as a Zend' Db row object on the member table, can you access it as:

  after $this->_data = $member;
  $this->emailAddress, instead of $this->_data->emailAddress ?
It doesn't work that way automatically.  You have to implement a __get() method in the current class, something like this:

public function __get($key)
{
  return $this->_data->$key;
}

Neriodavid(Wei Dai) wrote:
And, also, in the register view, when we assigned the view variable
emailAddress etc, so use the echo $this->escape($this->emailAddress) do not
generate an undefined variable warning?
It looks like Zend_View_Abstract has a method strictVars().  By default, Zend_View will return null if you specify a variable that hasn't been defined.  If you call $view->strictVars(true), then subsequent references to undefined variables raise an E_USER_NOTICE error.

Regards,
Bill Karwin

Re: some simple questions

by Neriodavid(Wei Dai) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Exactly!

Thank you!

On Tue, Jul 15, 2008 at 1:48 AM, Bill Karwin <bill@...> wrote:



Neriodavid(Wei Dai) wrote:
>
>    If a class has a protected member/property, say _data, which be
> assigned
> to as a Zend' Db row object on the member table, can you access it as:
>
>   after $this->_data = $member;
>   $this->emailAddress, instead of $this->_data->emailAddress ?
>

It doesn't work that way automatically.  You have to implement a __get()
method in the current class, something like this:

public function __get($key)
{
 return $this->_data->$key;
}


Neriodavid(Wei Dai) wrote:
>
> And, also, in the register view, when we assigned the view variable
> emailAddress etc, so use the echo $this->escape($this->emailAddress) do
> not
> generate an undefined variable warning?
>

It looks like Zend_View_Abstract has a method strictVars().  By default,
Zend_View will return null if you specify a variable that hasn't been
defined.  If you call $view->strictVars(true), then subsequent references to
undefined variables raise an E_USER_NOTICE error.

Regards,
Bill Karwin
--
View this message in context: http://www.nabble.com/some-simple-questions-tp18448329p18449186.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: some simple questions

by Matthew Ratzloff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I haven't read the book, but several of the reviews on Amazon [1] mention errors in the code examples.  I would trust your instincts when you run across something in the book that doesn't seem right.

-Matt

[1] http://www.amazon.com/review/product/0973862157/ref=cm_cr_dp_all_helpful?_encoding=UTF8&coliid=&showViewpoints=1&colid=&sortBy=bySubmissionDateDescending

On Mon, Jul 14, 2008 at 10:04 AM, Neriodavid(Wei Dai) <neriodavid@...> wrote:
Hi,
   Does anyone read the Cal Evans book, php|a's Guide to Programming with Zend Framework?
  
   I have some simple questions just want to make clear:

   If a class has a protected member/property, say _data, which be assigned to as a Zend' Db row object on the member table, can you access it as:

  after $this->_data = $member;
  $this->emailAddress, instead of $this->_data->emailAddress ?

  If you read the book, check out the chapter4's sample code, suddenly, we can directly access the $member->emailAdress?


  And, also, in the register view, when we assigned the view variable emailAddress etc, so use the echo $this->escape($this->emailAddress) do not generate an undefined variable warning?

These may stupid simple question, but these kind thing I never do. I check the code, does somewhere in the ZF has utilized the magic method, such as __get or __set to automatically handle this?

Thanks.

LightInTheBox - Buy quality products at wholesale price