私はphp5とZend Frameworkの初心者で、Zend Studioを使用しています。多くのドキュメントを読みましたが、Zend のコントローラーの背後にある概念をまだ理解できません。
簡単に説明すると、アカウント処理用の小さな Web アプリケーションを開発しようとしています。デフォルトの index.php ファイルに変更を加えていません。ここにあります:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
||define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv ('APPLICATION_ENV'): 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/* function _initView()
{
$view = new Zend_View();
$view->addScriptPath(APPLICATION_PATH . '/views/scripts/');
} */
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
ここに私のIndexController.phpがあります
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
}
}
コンセプトが理解できないので、そこにも変更を加えていません。
私のindex.phtml:
<html>
<style>
</style>
<body>
<img alt="" src="http://localhost/Accounts/application/views/scripts/images/logo.png">
<div id="text" >
<h1>Welcome</h1><br><hr>
<h4>Please Log In To View The Main Page</h4></div><br><br><br>
<form action="main/main" method="post"><center><table>
<tr>
<td>User Name :</td> <td><input type="text" name="uname"/></td>
</tr>
<tr>
<td>Passowrd :</td> <td><input type="password" name="pwd"/></td>
</tr>
<tr>
<td><center><input type="submit" value="Log In"/></center></td> <td><center><input type="reset" value="Cancel"/></center></td>
</tr>
</table></center></form>
</body>
</html>
**私が指定したことに注意してください
<form action="main/main">
次のページ、「main.phtml」に移動します。しかし、これはうまくいきません。
ここに私のMainController.phpがあります:
<?php
require_once ('library/Zend/Controller/Action.php');
class MainController extends Zend_Controller_Action {
public function init()
{
/* Initialize action controller here */
}
public function mainAction()
{
include 'views/scripts/main/main.phtml';
}
}
上記のコントローラーで、指定すると、
include 'views/scripts/main/main.phtml';
そうでなくても、同じように機能します。ブラウザでログインしようとしても何も表示されません。
ログインの条件を指定していないので、これは main.phtml を表示するはずだと思います。
ここにあります:
<html xmlns="http://www.w3.org/1999/xhtml" lang = "en">
<style>
</style>
<head>
<meta name="keywords" content="" /></meta>
<meta name="description" content="" /></meta>
<link rel="shortcut icon" href="http://localhost/Accounts/application/views/scripts/images/favicon.ico" >
<title>Accounts Handling</title>
</head>
<body>
<div id="header"></div>
<div id="main">
<div id="menu">
<?php include ('C:\wamp\www\Accounts\application\views\scripts\header\header.php');?>
</div>
<div id="content">
<center><img src="http://localhost/Accounts/application/views/scripts/images/accounts.jpg" alt="image" height=600px width=550px/></center>
</div>
<div>
<?php include ('C:\wamp\www\Accounts\application\views\scripts\footer\footer.php');?>
</div>
</div>
</body>
</html>
私のコードで何が問題になっていますか? なぜこれが機能しないのですか?私が理解する必要があるのは、これらのコントローラーがどのように機能するかです。ビューをどのようにリンクしますか?