如何向此zend项目添加页面

时间:2013-04-18 06:54:28

标签: php zend-framework

所以我被分配到使用Zend Framework 1.12的这个项目。我正在尝试向项目添加页面,但我似乎在某处丢失了某些内容。目录结构与我见过的任何Zend项目(没有bootstrap目录)有点不同。

-application

---控制器

------模块

---------------的nopage

------------------------ IndexController.php

---模型

----一堆db文件

---观看

---- templates(smarty tpl文件)

---------------的nopage

------------------------ nopage.tpl

---后端

---- router.php

这是我的router.php代码

$controller -> addControllerDirectory(ROOT . 'application/controller/nopage', 'nopage');
$router = $controller -> getRouter();

$nopage = new Zend_Controller_Router_Route_Regex(
'nopage.html',
array('module' => 'nopage', 'controller' => 'index', 'action' => 'index')
);

$router -> addRoute('nopage', $nopage);

这是我的IndexController代码,用于nopage IndexController.php

<?php

/** Zend_Controller_Action */
Zend_Loader::loadClass('System_Controller_Action');


class Nopage_IndexController extends System_Controller_Action 
{   

public function indexAction() {

            $this -> smarty -> assign('PageBody', 'nopage/404.tpl');
            $this -> smarty -> assign('Title', 'PetIdMe - 404');
            $this -> smarty -> display('layouts/main.tpl');
    } 
}

我收到此错误:

指定的控制器无效(索引)

我的代码似乎遵循相同的结构和所有其他路线所做的一切,我搜索并搜索无济于事。 SO的知识渊博和慷慨的人在这里有什么想法吗?如果您需要更多信息,我很乐意提供。非常感谢您提前了解这一点。

编辑来自路由器的一些额外代码

$controller -> addControllerDirectory(ROOT . 'application/controllers/lostandfound',      'lostandfound');

$controller -> addControllerDirectory(ROOT . 'application/controllers/search', 'search');

$controller -> addControllerDirectory(ROOT . 'application/controllers/orderstatus', 'orderstatus');

$controller -> addControllerDirectory(ROOT . 'application/controllers/myaccount', 'myaccount');


$controller -> addControllerDirectory(ROOT . 'application/controllers/giftcard', 'giftcard');

$controller -> addControllerDirectory(ROOT . 'application/controller/nopage', 'nopage');



$router = $controller -> getRouter();


$nopage = new Zend_Controller_Router_Route(
'nopage.html',
array('module' => 'nopage', 'controller' => 'index', 'action' => 'index')
);

$router -> addRoute('nopage', $nopage);
//****************** Gift Card ************************************************************

$giftcard = new Zend_Controller_Router_Route_Regex(
'giftcard.html',
array('module' => 'giftcard', 'controller' => 'index', 'action' => 'index')
);
$router -> addRoute('giftcard', $giftcard);

$GiftCardsPages = new Zend_Controller_Router_Route_Regex(
'admin/gift/page/(\d*)',
array('module'=>'admin', 'controller'=>'gift', 'action'=>'index'),
array(1  =>'page')
);
$router -> addRoute('GiftCardsPages', $GiftCardsPages);

//****************** SEARCH ***************************************************************
$topsearchserult = new Zend_Controller_Router_Route_Regex(
'topsearchserult.html',
array('module'=>'search', 'controller'=>'index', 'action'=>'search'),
array(1  =>'page')
);
$router -> addRoute('topsearchserult', $topsearchserult);

//****************** MY ACCOUNT *********************************************************

$myaccount = new Zend_Controller_Router_Route_Regex(
'myaccount.html',
array('module' => 'myaccount', 'controller' => 'index', 'action' => 'index')
);
$router -> addRoute('myaccount', $myaccount);

和其他一些IndexController页面:

Zend_Loader::loadClass('System_Controller_Action');

class News_IndexController extends System_Controller_Action {

public function init() {
    parent::init();
}

public function viewAction() {
    $new = $this -> News -> getNewById($this->_getParam('new_id'));
    $this->smarty->assign('new', $new);
    $this->smarty->assign('Title', $new['new_title']);
    $this->smarty->assign('PageBody', 'news/show_item.tpl');
    $this->smarty->display('layouts/main.tpl');
}

public function indexAction() {

    $page = $this->_hasParam('page')?((int)$this->_getParam('page')-1):0; 
    $items = $this->News->getNewsForPage($page);

    $this->smarty->assign('items', $items);
    $this->smarty->assign('Title', 'News items');
    $this->smarty->assign('page_num', $page+1);
    $this->smarty->assign('page_count', $this->News->getPagesCount());
    $this->smarty->assign('PageBody', 'news/index.tpl');
    $this->smarty->display('layouts/main.tpl');
}

和另一个

Zend_Loader::loadClass('System_Controller_Action');
include_once ROOT . 'application/models/GiftCardsDb.php';
class GiftCard_IndexController extends System_Controller_Action 
{
private $giftcard;
 public function init() {
    $this->giftcard = new GiftCardDb();
    parent::init();
}

public function indexAction() {
    if($this->_hasParam('product_id')){
        $this -> smarty -> assign('giftcard_text', $this -> Content ->     getPageByLink('giftcard.html'));
        $this -> smarty -> assign('giftcard_agreement_text', $this -> Content -> getPageByLink('giftcard_agreement.html'));
        $this -> smarty -> assign('PageBody', 'giftcard/index.tpl');
        $this -> smarty -> assign('product_id', $this->_getParam('product_id'));
        $this -> smarty -> assign('Title', 'Pet Id Me - Gift Card');
        $this -> smarty -> display('layouts/main.tpl');
    } else {
        $this->_redirect("/");
    }
    }

2 个答案:

答案 0 :(得分:0)

你添加zend框架额外的页面给出了一些步骤

1.zend是MVC模式

2.创建视图文件名和控制器文件名同名

示例:view-&gt; save.phtml 控制器:saveAction

3.您包括数据库连接实现控制器(或)调用db方法   参考以下链接      http://www.phpeveryday.com/articles/Zend-Framework-Basic-Tutorial-P840.html

答案 1 :(得分:0)

我认为解决方案是添加此行

Zend_Loader::loadClass('System_Controller_Action');

在IndexController的开头。即

Zend_Loader::loadClass('System_Controller_Action');

class Nopage_IndexController extends System_Controller_Action 
{