0

所以我被分配到这个使用 Zend Framework 1.12 的项目。我正在尝试向项目添加一个页面,但我似乎在某处遗漏了一些东西。目录结构与我见过的任何示例 Zend 项目都有点不同(没有引导目录)。

-应用

---控制器

------模块

---------------无页

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

- -模型

----一堆db文件

---观看次数

----模板(智能 tpl 文件)

---------------无页

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

---后端

----路由器.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);

这是我的 nopage IndexController.php 的 IndexController 代码

<?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("/");
    }
    }
4

2 回答 2

0

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

1.zend是MVC模式

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

示例:view->save.phtml 控制器:saveAction

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

于 2013-04-18T07:15:34.983 回答
0

我认为解决方案是添加这一行

Zend_Loader::loadClass('System_Controller_Action');

在 IndexController 的开头。IE

Zend_Loader::loadClass('System_Controller_Action');

class Nopage_IndexController extends System_Controller_Action 
{
于 2013-04-18T07:35:43.900 回答