菜鸟用ZF遇到的怪现象

tooh 2010-04-06 12:31:10
怪现象一:IDE(zend studio 7.1)能发现我在models下面定义的类Albums,
class Albums extends Zend_Db_Table_Abstract {
protected $_name = 'albums';
}

而我编译的时候说找不到Albums类
如下是我的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(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts'));

Zend_Loader::registerAutoload();
//load config
$config = new Zend_Config_Ini('../application/config.ini','general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);

/*regist db*/
//setup database
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);
/*end*/

//setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory('./application/controllers');
$frontController->throwExceptions(true);

// 可以解决UTF8或者其他语系的显示乱码问题,老版本这样可以解决,新版本设置更简单.
$db->query("SET NAMES 'utf8'");
$application->bootstrap()
->run();

怪现象二
我在
public function indexAction()
{
$this->view->title = "my Albums";
include('./zend/application/models/Albums.php');
$albums = new Albums();
$this->view->albums = $albums->fetchAll();
}
添加了这一句后用script调试又出新问题了,我数据库里的列的名称会变,
<?php foreach ($this->albums as $album):?>
<tr>
<td><?php echo $this->escape($album->title);?></td>
<td><?php echo $this->escape($album->artist);?></td>
<td>
<a href="<?php echo $this->url(array('controller'=>'index',
'action'=>'edit', 'id'=>$album->id));?>"/>Edit</a>
<a href="<?php echo $this->url(array('controller'=>'index',
'action'=>'delete','id'=>$album->id));?>">Delete</a>
</td>
</tr>
<?php endforeach;?>
我用debug模式查看第一次得到的列名是跟数据库一致的,但是第二次title列就变成了albums了,接着就是抛出异常。

备注:我从网上下了一个教程学着做,他用的版本是1.8的,我的是最新的。
...全文
124 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tooh 2010-04-06
  • 打赏
  • 举报
回复
自己顶一个
garcon1986 2010-04-06
  • 打赏
  • 举报
回复
顶~~~~~~·····

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧