如何在 zend 框架中使用 extends Zend_Db_Table_Abstract 来使用多个 $_name
我们尝试这样做,但它显示了一些错误。我们的表名称是用户和消息。
<?php
class Application_Model_childconnect1 extends Zend_Db_Table_Abstract
{
protected $_name = 'users';
public function loginvalidation($username,$pwd)
{
$row = $this->fetchRow('UserName = \'' . $username . '\'and UserPW = \''. $pwd . '\'');
if (!$row)
{
$msg="invalid";
return $msg;
}
else
{
return $row->toArray();
}
}
protected $_name = 'messages';
public function replymessage($message)
{
$data=array(
'MessageText'=>$message
);
$this->insert($data);
}
}
we tried to do like this,but it is showing some errors.Our table names are users and messages.
<?php
class Application_Model_childconnect1 extends Zend_Db_Table_Abstract
{
protected $_name = 'users';
public function loginvalidation($username,$pwd)
{
$row = $this->fetchRow('UserName = \'' . $username . '\'and UserPW = \''. $pwd . '\'');
if (!$row)
{
$msg="invalid";
return $msg;
}
else
{
return $row->toArray();
}
}
protected $_name = 'messages';
public function replymessage($message)
{
$data=array(
'MessageText'=>$message
);
$this->insert($data);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Zend_Db_Table
是一个表数据网关,根据定义是这又意味着每个表有一个类,并且每个类不能有多个名称。请参阅 Zend Framework 参考指南以了解如何正确使用它:
Zend_Db_Table
is a Table Data Gateway, which by definition iswhich in turn means you have one class per table and cannot have multiple names per class. See the Zend Framework Reference Guide to learn how to use it properly:
虽然欢迎您按照自己的方式设置应用程序,但您可能需要考虑使用 Zend Auth 处理身份验证。
除此之外,如果您打算一般使用 ZF,那么可以利用 Zend_Db_Select 类可能会有所帮助。
如果您确实想手动生成 SQL,也可以这样做。只需使用 Zend_Db_Adapter< 的 query 方法即可/a> 对象。
While you are welcome to setup the application as you have, you may want to look into using Zend Auth to handle authentication.
That aside if you are going to be making use of ZF in general then taking advantage of the Zend_Db_Select class can be helpful.
If you really want to generate the SQL by hand you can do so as well. Just use the query method of the Zend_Db_Adapter Object.