2012-06-22 87 views
1

我遵循以下documentation,我遇到了问题。我访问的网址为localhost/epos和索引页面正常工作。但是,如果我做本地主机/ EPOS/pgeline2d我得到错误指定的控制器无效() - Zend Framework

An error occurred 
Page not found 
Exception information: 

Message: Invalid controller specified (epos) 
Stack trace: 

#0 /opt/eposdatatransfer/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#1 /opt/eposdatatransfer/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#2 /opt/eposdatatransfer/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#3 /opt/eposdatatransfer/public/index.php(26): Zend_Application->run() 
#4 {main} 

Request Parameters: 

array (
    'controller' => 'epos', 
    'action' => 'guestbook', 
    'module' => 'default', 
) 

我SQLLite数据库表名叫做“PGE_Line2D”。下面是我的文件:

的httpd.conf

Alias /epos "/opt/eposdatatransfer/public" 

<Directory "/opt/eposdatatransfer/public"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
</Directory> 

应用/ CONFIGS /的application.ini

[production] 
phpSettings.display_startup_errors = 0 
phpSettings.display_errors = 0 
includePaths.library = APPLICATION_PATH "/../library" 
bootstrap.path = APPLICATION_PATH "/Bootstrap.php" 
bootstrap.class = "Bootstrap" 
appnamespace = "Application" 
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" 
resources.frontController.params.displayExceptions = 0 
phpSettings.date.timezone = "Europe/London" 
resources.db.adapter = "PDO_SQLITE" 
resources.db.params.dbname = APPLICATION_PATH "/../data/db/h3111142.db" 

[staging : production] 

[testing : production] 
phpSettings.display_startup_errors = 1 
phpSettings.display_errors = 1 

[development : production] 
phpSettings.display_startup_errors = 1 
phpSettings.display_errors = 1 
resources.frontController.params.displayExceptions = 1 

应用/ bootstrap.php中

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {} 

应用程序/视图/脚本/index/index.phtml

hello 

应用/视图/脚本/ PGE-线-2D/index.phtml

<br /><br /> 
<div id="view-content"> 
    <p>View script for controller <b>PgeLine2D</b> and script/action name <b>index</b></p> 
    <?php foreach ($this->entries as $entry): ?> 
    <dt><?php echo $this->escape($entry->pga_id) ?></dt> 
    <?php endforeach ?> 
</div> 

应用/模型/ PGLine2D.php

class Application_Model_PgeLine2D 
{ 
    protected $_PGA_Id ; 
    protected $_PGA_Name ; 

    public function __construct(array $options = null) 
    { 
     if (is_array($options)) { 
      $this->setOptions($options); 
     } 
    } 

    public function __set($name, $value){ 
     $method = 'set' . $name; 
     if (('mapper' == $name) || !method_exists($this, $method)) { 
      throw new Exception('Invalid set PgeLine2D property'); 
     } 
     $this->$method($value); 
    } 

    public function __get($name){ 
     $method = 'get' . $name; 
     if (('mapper' == $name) || !method_exists($this, $method)) { 
      throw new Exception('Invalid get PgeLine2D property'); 
     } 
     return $this->$method(); 
    } 

    public function setOptions(array $options) 
    { 
     $methods = get_class_methods($this); 
     foreach ($options as $key => $value) { 
      $method = 'set' . ucfirst($key); 
      if (in_array($method, $methods)) { 
       $this->$method($value); 
      } 
     } 
     return $this; 
    } 

    public function setPGA_Id($id){ 
     $this->PGA_Id = $id; 
     return $this; 
    } 

    public function getPGA_Id(){ 
     return $this->PGA_Id; 
    } 

    public function setPGA_Name($name){ 
     $this->PGA_Name = $name; 
     return $this; 
    } 

    public function getPGA_Name(){ 
     return $this->PGA_Name; 
    } 


} 

应用/模型/ PGLine2DMapper.php

class Application_Model_PgeLine2DMapper 
{ 
    protected $_dbTable; 

    public function setDbTable($dbTable) 
    { 
     if (is_string($dbTable)) { 
      $dbTable = new $dbTable(); 
     } 
     if (!$dbTable instanceof Zend_Db_Table_Abstract) { 
      throw new Exception('Invalid table data gateway provided'); 
     } 
     $this->_dbTable = $dbTable; 
     return $this; 
    } 

    public function getDbTable() 
    { 
     if (null === $this->_dbTable) { 
      $this->setDbTable('Application_Model_DbTable_PgeLine2D'); 
     } 
     return $this->_dbTable; 
    } 

    public function save(Application_Model_PgeLine2D $pgeLine2D) 
    { 
     $data = array(
       'PGA_Name' => $pgeLine2D->getPGA_Name() 
     ); 

     if(null === ($id = $pgeLine2D->getPGA_Id())) { 
      unset($data['id']); 
      $this->getDbTable()->insert($data); 
     } else { 
      $this->getDbTable()->update($data, array('PGA_Id = ?' => $id)); 
     } 
    } 

    public function find($id, Application_Model_PgeLine2D $pgeLine2D) 
    { 
     $result = $this->getDbTable()->find($id); 
     if (0 == count($result)) { 
      return; 
     } 
     $row = $result->current(); 
     $pgeLine2D->setPGA_Id($row->PGA_Id) 
      ->setPGA_Name($row->PGA_Name); 
    } 

    public function fetchAll() 
    { 
     $resultSet = $this->getDbTable()->fetchAll(); 
     $entries = array(); 
     foreach ($resultSet as $row) { 
      $entry = new Application_Model_PgeLine2D(); 
      $entry->setPGA_Id($row->PGA_Id) 
       ->setPGA_Name($row->PGA_Name); 
      $entries[] = $entry; 
     } 
     return $entries; 
    } 

} 

application/models/DbTable/PGLine2D.php

class Application_Model_DbTable_PgeLine2D extends Zend_Db_Table_Abstract 
{ 

    protected $_name = 'PGE_Line2D'; 


} 

应用/控制器/ PgeLine2DController.php

class PgeLine2DController extends Zend_Controller_Action 
{ 

    public function init() 
    { 
     /* Initialize action controller here */ 
    } 

    public function indexAction() 
    { 
     // action body 
     $pgeLine2D = new Application_Model_PgeLine2DMapper(); 
     $this->view->entries = $pgeLine2D->fetchAll(); 
    } 


} 
+0

我猜这实际上是一个配置问题:你的应用程序文件(控制器,视图脚本等)甚至没有被HTTP请求触及,它就会失败。所以,如果你将你的.php文件移出它,你的问题会更加清晰 - 只是一个建议。 – raina77ow

+0

......但可能并非如此。尝试将您的PgeLine2DController重命名为更简单的东西 - 例如pgeController,并相应地更改链接('localhost/epos/pge /')。它会改变什么吗? – raina77ow

+0

@ raina77ow我试着重命名它。没有什么区别。我也遵循使用留言簿示例的文档。那也没有工作 – shorif2000

回答

1

当您使用别名,而不是新的领域,你必须添加

resources.frontController.baseUrl = "/epos" 

到你的config.ini文件。

+0

谢谢你一直工作。 Im新的zend - 我将如何从索引转发到/ pge。你知道更好的在线教程,为这个 – shorif2000

+0

Artur添加css和jquery,这解决了我遇到的一个问题 - 谢谢! ...但它让我到一个登录页面,而不是主页。有什么我需要得到的别名解析为主页? – gtr1971

+0

你的意思是application.ini而不是config.ini? – Sydwell

相关问题