Variable declaration / definition
To access a variable you have to declare it from your controller section & then you can use this variable in the view section.

Usage: Controller page

public function nameAction()
{
$request = $this->getRequest();
$this->view->assign(‘name’, ‘Sandipan Bhattacharjee’); // we assign a value to the name variable
$this->view->assign(‘gender’,’Male’); // we assign a value to the gender variable

$this->view->assign(‘title’, ‘User Name’);
}

Usage: View page[name.phtml]

<?php echo $this->escape($this->name); ?>
<?php echo $this->escape($this->gender); ?>
<?php echo $this->escape($this->title); ?>

Full controller

require_once ‘Zend/Controller/Action.php’;
require_once ‘Zend/Auth.php’;
require_once ‘Zend/Auth/Adapter/DbTable.php’;
class UserController extends Zend_Controller_Action
{
public function nameAction()
{
$request = $this->getRequest();
$this->view->assign(‘name’, ‘Sandipan Bhattacharjee’); // we assign a value to the name variable
$this->view->assign(‘gender’,’Male’); // we assign a value to the gender variable

$this->view->assign(‘title’, ‘User Name’);
}

}

Explanation:
1. The above 3 files are library files which requires to run this application , so we have to include the above 3 files
2. Then we create a class rather controller class which extends Zend_ Controller _Action
3. The Class file holds many action controller method
4. The view files are created under the user folder because our class name is UserController & the Controller class file name is UserController.php
5. We have to follow the naming convention
like : Controller class name must be in camel case
Controller method name will be view file name followed by the extension phtml
How to see this in the browser

http://localhost/zend/user/name

http://sever address / folder name /controller name / action controller method

Latest posts by Sandipan Bhattacharjee

  • Share/Bookmark