+ Reply to Thread
Results 1 to 2 of 2

Thread: PHP OOP question

  1. #1
    umair862 is offline Junior Member
    Join Date
    May 2009
    Posts
    11

    Default PHP OOP question

    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. #2
    Tekerson is offline Senior Member
    Join Date
    Jul 2008
    Posts
    288

    Default

    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

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts