起初我只是在显示我的表单时遇到问题然后我在我的项目的index.php中编辑了set_include_path,但它没有帮助所以我从set_include_path中删除了表单的路径并恢复了我的旧代码,但现在它是jus在每个模块上显示一个blanck页面。这是我的Bootstarp
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public $frontController= null;
public $root='';
public $layout=null;
public $config = null;
public function run(){
$this->setUpEnvironment();
$this->prepare();
$response = $this->frontController->dispatch();
$this->sendResponse($response);
}
public function setUpEnvironment(){
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
date_default_timezone_set('Asia/Kuala_Lumpur');
$this->root = dirname(dirname(__FILE__));
echo $this->root."hello";
}
public function setUpConfiguration(){
$this->config = new Zend_Config_Ini($this->root.'/application/configs/application.ini');
}
public function prepare(){
$this->setupEnvironment();
//Zend_Loader::registerAutoload();
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
$this->setupRegistry();
$this->setupConfiguration();
$this->setupFrontController();
$this->startSession();
$this->setupView('default');//current theme direcotry
//$this->setupLanguage();
}
public function setupFrontController(){
Zend_Loader::loadClass('Zend_Controller_Front');
$this->frontController = Zend_Controller_Front::getInstance();
$this->frontController->throwExceptions(true);
$this->frontController->returnResponse(true);
$this->frontController ->setParam('noErrorHandler', true);
//echo $this->root;
$this->frontController->setControllerDirectory(array(
'default' => $this->root .'/application/default/controllers/',
'admin' => $this->root .'/application/admin/controllers/',
//'vendor' => $this->root .'/application/vendor/controllers/',
));
}
public function setupView($crt_theme)
{
$view = new Zend_View;
$view->setEncoding('UTF-8');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
$view->setScriptPath($this->root .'/application/default/views/scripts/'.$crt_theme);
$view->setHelperPath($this->root .'/application/default/views/helpers');
$this->layout = Zend_Layout::startMvc(
array(
'layoutPath' => $this->root . '/application/layouts',
'layout' => 'layout'
)
);
$this->registry->set("theme", $crt_theme);
}
public function setupRegistry()
{
$this->registry = Zend_Registry::getInstance();
$this->registry->set('config', $this->config);
$this->registry->set('frontController',$this->frontController);
}
public function startSession(){
Zend_Session::start();
}
public function sendResponse(Zend_Controller_Response_Http $response)
{
$response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
$response->sendResponse();
}
}
我已经制作了两个模块admin和default并在application / forms / Admin / LoginForm.php中创建了一个表单
<?php
class Application_Form_Admin_LoginForm extends Zend_Form{
public function init(){
$this->setMethod('post')
->setAction('/admin/index');
$this->addElement(
'text', 'username', array(
'label' => 'Username:',
'required' => true,
'filters' => array('StringTrim'),
));
$this->addElement('password', 'password', array(
'label' => 'Password:',
'required' => true,
));
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Login',
));
}
}
这是管理模块中的IndexController
<?php
class Admin_IndexController extends Zend_Controller_Action
{
public function init()
{
// echo "Hello";
$this->layout = Zend_Layout::startMvc(
array(
'layoutPath' => APPLICATION_PATH . '/layouts',
'layout' => 'layout'
)
);
//var_dump($this->layout);
//$this->view->('header.phtml');
}
public function indexAction()
{
$form = new Application_Form_Admin_LoginForm();
/*$form->setMethod('post');
$form->addElement(
'text', 'username', array(
'label' => 'Username:',
'required' => true,
'filters' => array('StringTrim'),
));
$form->addElement('password', 'password', array(
'label' => 'Password:',
'required' => true,
));
$form->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Login',
));
*/
$this->view->login = $form;
// $this->view->show = "I'm in admin index controller";
/*if((!isset($this->_request->getParam('username')))&&(!isset($this->_request->getParam('password'))))
{
}
else{
$username = $this->_request()->getPost('username');
echo $username;
}
*/
}
}
这是我在index / admin / views / scripts /
的索引文件夹中的index.phtml<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<style>
body{
background-color:grey;
}
#login{
background-color:#FFF;
width:350px;
height:200px;
border:1px solid black;
-moz-border-radius:10px;
border-radius:10px;
}
</style>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<center>
<h1>Please Login</h1>
<div id="login">
<?php
echo $this->login;
//echo $this->show;
?>
</center>
</div>
</body>
</html>