Zend Frameworkを使用してWebサイトを作成しようとしています。これは、非常に優れていると聞き、フレームワークを試してみたいと思ったためですが、単純な問題で頭がおかしくなりました。
HTMLを表示する以外に何もする必要がないので、静的コンテンツを含む単純なmywebsite.com/aboutページを作成したいと思います。
Aboutコントローラーとそれに関連付けられたphtmlを作成しましたが、/ aboutに移動しようとすると、404エラーが発生し、その後に次のメッセージが表示されます。
The requested controller could not be mapped to an existing controller class.
Controller:
not-found(resolves to invalid controller class or alias: not-found)
そこで、ルーティングファイルを確認しました。
'router' => array(
'routes' => array(
'about' => array(
'type' => 'segment',
'options' => array(
'route' => '/about',
),
'defaults' => array(
'controller' => 'About\Controller\About',
'action' => 'index',
),
),
),
),
ですから、私が間違っていなければ、これは私が作成したAboutコントローラーを呼び出すことになっていますが、問題を見つけることができません。
誰かが私がZendで見逃したことや得られなかったことを理解するのを手伝ってくれるなら、私はとてもうれしく思います。
編集:それが何かを変更する場合、Zendのバージョンは2.xです
#編集2:ジェームズケントの助けを借りて解決策を見つけました
私のルーティングファイルは間違っているようでした、ここに新しいものがあります:
'router' => array(
'routes' => array(
'about' => array(
'type' => 'Literal',
'options' => array(
'route' => '/about',
'defaults' => array(
'__NAMESPACE__' => 'About\Controller',
'controller' => 'About',
'action' => 'index',
),
),
),
),
),
また、AboutコントローラーのindexActionを変更する必要がありました。
class AboutController extends AbstractActionController
{
public function nolayoutAction() {
$viewModel = new ViewModel();
//$viewModel->setTerminal(true); Uncomment to disable the layout
return $viewModel;
}
public function indexAction()
{
$viewModel = $this->nolayoutAction();
return $viewModel;
}
}
それが何人かの人々に役立つことを願っています。