phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Zend Framework Action: URL Structure and Controller

Tag: framework, zend, zend framework, actions, url structure, controller   Category: PHP Framework
post: 11 Apr 2008 read: 569


Zend Framework Action Step By Step Tutorial - Part 2: URL is important part when we develop web application. We use them for jump between pages. As we know, every framework have rule about URL. It is a key to understanding how the framework works. Now, we will talk rule at Zend Framework.

Zend Framework breaks URL into pieces. Those pieces are laid out as follows: http://hostname/controller/action/parametes. Look at our url that we used to access hello page: http://localhost/test/zend/helloworld/web_root/. Assume http://hostname is same with http://localhost/test/zend/helloworld/web_root/. Next path is controller. Try to point your browser to http://localhost/test/zend/helloworld/web_root/index. We get same with http://localhost/test/zend/helloworld/web_root/. Why? as default, http://localhost/test/zend/helloworld/web_root/ will access index controller. Can you catch idea?

I know, you don't patient to test with other controller. How about we use other controller named "user"? Never mind. From theory above, we will access with http://localhost/test/zend/helloworld/web_root/user. Let's do it.

First, create controller name "UserController". Create a file named "UserController" within application/controllers. Enter following code:


<?php
require_once 'Zend/Controller/Action.php';

class UserController extends Zend_Controller_Action
{
  public function indexAction()
  {
    $this->view->assign('name', 'Wiwit');
    $this->view->assign('title', 'Hello');
  }
    
}
?>

Next, create a folder named "user" within helloworld\application\views\scripts. Create a file named "index.phtml" within user. Enter following code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo $this->escape($this->title); ?></title>
</head>

<body>
  <h1><?=$this->escape($this->title);?>, <?=$this->escape($this->name);?></h1>
</body>
</html>

Now, point your browser to http://localhost/test/zend/helloworld/web_root/user.



Series this article:
Zend Framework Action: Dynamic Content
Zend Framework Action: URL Structure and Controller
Zend Framework Action: URL Structure and Action
Zend Framework Action: GET Parameters
Zend Framework Action: Including Header and Footer

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
CAPTCHA - part 3 : "Are you human or ....?" (Build Your CAPTCHA)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting