开发者

Zend Framework Subdirectory

Hey so in Zend Framework I have a controller called Days and I have an action called sunday.

So when I go to my website: mywebsite.com/days/sunday/ - this is going to be using my default index.phtml which is fine.

Now I hav开发者_如何学运维e another phtml page called goodmorning which I want it to remain in the sunday action.

so it reads like this:

mywebsite.com/days/sunday/goodmorning/

mywebsite.com/days/sunday/goodafternoon/

mywebsite.com/days/sunday/night/

How do I do that?

  class daysController extends Zend_Controller_Action

  {

      public function sundayAction()

      {



      }

  }


class DaysController extends Zend_Controller_Action
{
    public function sundayAction()
    {
        $params = getParams();
        switch ($params[0]) {
            case 'goodmorning':
                $partial = 'goodmorning';
                break;
            case 'goodafternoon':
                $partial = 'goodafternoon';
                break;
            case 'night':
            default:
                $partial = 'night';
                break;
        }
        $this->_helper->viewRenderer($partial);
    }
}

Although, you should use http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.usage to set up a custom route. days/:day/:greeting for example.


So when I go to my website: mywebsite.com/days/sunday/ - this is going to be using my default index.phtml which is fine.

Wrong, it'll call sunday.phtml, views are mapped with actions

However, depending on the involved parameters, you may both use the Zend_Controller_Action::render() method or use $this->partial('goodmorning.phtml') in your view, it may have sense is you've some common part between all the views and want to change only the remaining part.

You may want to describe more accurately what you want to do, and we may suggest you a better approach actually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜