0

そのため、Zend Framework 1.12 を使用するこのプロジェクトに割り当てられました。プロジェクトにページを追加しようとしていますが、何かが足りないようです。ディレクトリ構造は、私が見た Zend プロジェクトの例とは少し異なります (ブートストラップ ディレクトリはありません)。

-応用

---コントローラー

------モジュール

---------------ノページ

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

- -モデル

---- db ファイルの束

---ビュー

----テンプレート (smarty tpl ファイル)

---------------ノページ

------------------------ 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);

これが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. データベース接続実装コントローラを含める (または) db メソッドを呼び出す 参照 フォロー リンク http://www.phpeveryday.com/articles/Zend-Framework-Basic-Tutorial-P840.html

于 2013-04-18T07:15:34.983 に答える