gpt4 book ai didi

php - 如何在 symfony 中使用数据库

转载 作者:行者123 更新时间:2023-11-30 00:25:44 25 4
gpt4 key购买 nike

我是 symfony 框架的新手,我正在使用老师推荐的 symfony1.4.20,现在的问题是,我无法将其查询到我的数据库。谁能帮我指出问题吗?

这是我的操作类中的代码,

class contentActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
$this->forward('default', 'module');
}
public function executeGetuser(){
$this->user_list = Doctrine::getTable('user')
->createQuery('u')
->execute();

foreach($this->user_list as $row) {
$id = $row->id;
$name = $row->name;
}
}
}

我收到如下错误,

500 | Internal Server Error | Doctrine_Exception
Couldn't find class user
stack trace

at ()
in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Table.php line 299 ...
{
$name = $this->_options['name'];
if ( ! class_exists($name) || empty($name)) {
throw new Doctrine_Exception("Couldn't find class " . $name);
}
$record = new $name($this);
at Doctrine_Table->initDefinition()
in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Table.php line 256 ...
at Doctrine_Table->__construct('user', object('Doctrine_Connection_Mysql'), 1)
in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connection.php line 1126 ...
at Doctrine_Connection->getTable('user')
in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Core.php line 1090 ...
at Doctrine_Core::getTable('user')
in SF_ROOT_DIR\apps\userlogin\modules\content\actions\actions.class.php line 32 ...
at contentActions->executeGetuser(object('sfWebRequest'))
in SF_SYMFONY_LIB_DIR\action\sfActions.class.php line 60 ...
at sfActions->execute(object('sfWebRequest'))
in SF_SYMFONY_LIB_DIR\filter\sfExecutionFilter.class.php line 92 ...
at sfExecutionFilter->executeAction(object('contentActions'))
in SF_SYMFONY_LIB_DIR\filter\sfExecutionFilter.class.php line 78 ...
at sfExecutionFilter->handleAction(object('sfFilterChain'), object('contentActions'))
in SF_SYMFONY_LIB_DIR\filter\sfExecutionFilter.class.php line 42 ...
at sfExecutionFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR\filter\sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR\filter\sfRenderingFilter.class.php line 33 ...
at sfRenderingFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR\filter\sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR\controller\sfController.class.php line 238 ...
at sfController->forward('content', 'getuser')
in SF_SYMFONY_LIB_DIR\controller\sfFrontWebController.class.php line 48 ...
at sfFrontWebController->dispatch()
in SF_SYMFONY_LIB_DIR\util\sfContext.class.php line 170 ...
at sfContext->dispatch()
in SF_ROOT_DIR\web\userlogin_dev.php line 13 ...

任何人都可以帮助我修复此错误并使代码在带有数据库的 symfony 中工作吗?

最佳答案

试试这个:

$this->user_list = Doctrine::getTable('User')

大写U

关于php - 如何在 symfony 中使用数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22904835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com