![]() |
|
|||
|
Hi,
I am new to OOP and i am really confused about something in ZF program. File -----Indexcontroller.php------ Code:
public $myNamespace;
public function websession()
{
$this->myNamespace = new Zend_Session_Namespace('Default');
if(isset($this->myNamespace->countPages))
{
$this->myNamespace->countPages++;
}
else
{
$this->myNamespace->countPages=1;
}
return $this->myNamespace->countPages;
}
public function indexAction()
{
/*$this->view->title = "Our Albums";
$this->view->headTitle($this->view->title, 'PREPEND');
$albums = new Model_DbTable_Albums();
$this->view->albums = $albums->fetchAll();*/
$this->view->message=$this->websession();
}
File-----index.phtml------ Code:
<h1>Message: <?php echo $this->message; ?></h1> Above code display the refresh button pressed for a session. It is working fine. However, I have a few question regarding OOP. File -----Indexcontroller.php------ 1. I have tried $this->view->message=$this->myNamespace->countPages; but it looks like message variable is not storing it. It is not dipslaying it on webpage. 2. Why are we using $this->view->message instead of just $this->message? What is view? File-----index.phtml------ 3. <h1>Message: <?php echo $this->message; ?> Why are we not using $this->view->message ? We have stored the output of session in $this->view->message on indexController page but we are using only $this->message on index.phtml. 4.what is $this->escape($this->message); escape function in zend framework? Please don't mind if i have asked stupid questions. I am new to OOP and ZF. Thank You, Umair |
|
|||
|
2. $this->view in the controller is a Zend_View object, so setting
[php]$this->view->message = "foo";[/php] is setting the value "foo" to the variable "message" on the view object. Whereas, $this->message would be the message variable of the controller object. 3. This is in a view script (.phtml). This file is part of a Zend_View object (the same Zend_View object as in #2). So $this->message is the message variable of the view object (which was set from the controller). 4. $this->escape() is a function of the view that escapes the data for html output. It's basically a wrapper around htmlentities.
__________________
Brenton Alker PHP Developer - Brisbane, Australia blog.tekerson.com | twitter.com/tekerson | brenton.mp |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Designed by: Miner Skinz |
Powered by vBulletin® Version 3.8.4 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.1.0 |
![]() |