Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将页面添加到此zend项目_Php_Zend Framework - Fatal编程技术网

Php 如何将页面添加到此zend项目

Php 如何将页面添加到此zend项目,php,zend-framework,Php,Zend Framework,所以我被分配到这个使用Zend Framework 1.12的项目。我正试图在项目中添加一个页面,但我似乎遗漏了一些东西。目录结构与我见过的任何示例Zend项目(无引导目录)都有点不同 -应用 ---控制器 ------模块 ---------------无页 ------------------------IndexController.php ---模型 ----一堆数据库文件 ---观点 ----模板(smarty tpl文件) ---------------无页 ------------

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

-应用

---控制器

------模块

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

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

---模型

----一堆数据库文件

---观点

----模板(smarty tpl文件)

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

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

---后端

----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);
这是我的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');
    } 
}
还有一些来自其他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("/");
    }
    }

在给定的一些步骤中,您可以添加zend framework额外页面

1.zend是MVC模式

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

示例:查看->保存.phtml 控制器:saveAction

3.包括数据库连接实现控制器(或)调用db方法 参考以下链接
我认为解决办法是增加这一行

Zend_Loader::loadClass('System_Controller_Action');
在IndexController的开始处。i、 e

Zend_Loader::loadClass('System_Controller_Action');

class Nopage_IndexController extends System_Controller_Action 
{

在$controller->addControllerDirectory中(ROOT.'application/controller/nopage','nopage');你能回显ROOT的值并告诉我你得到了什么吗?根路径是正确的,大约有30个其他的“$controller->addControllerDirectory(ROOT.“application/controller/XXX”,“XXX”);”在路由器中,你可以粘贴任何其他示例,说明你是如何为任何其他页面设置路由的。您必须正确使用它们?编辑以显示更多示例。为什么您使用新的Zend_控制器\u路由器\u路由,而在其他地方它是新的Zend_控制器\u路由器\u路由\u正则表达式?它就在那里,只是在示例中格式化,没有显示为代码。然后您可以尝试清除存储文件夹中的缓存文件夹吗(我希望如此)可能是在向路由添加新配置时,需要路由不从缓存中拾取。不确定但试一试?我正在研究如何做到这一点,如果我在中更改控制器:$nopage=new Zend\u controller\u Router\u Route\u Regex('nopage.html',array('module'=>'nopage','controller'=>'index','action'=>'index')$路由器->添加路由('nopage',$nopage);它改变了错误。还有什么原因可能导致这种情况?指定的控制器无效(插入我将控制器数组值更改为此处的内容)