开发者

how to use multiple $_name using extends Zend_Db_Table_Abstract in zend frame work

开发者 https://www.devze.com 2022-12-25 21:19 出处:网络
we tried to do like this,but it is showing some errors.Our table names are users and messages. <?php

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);
      }


}


Zend_Db_Table is a Table Data Gateway, which by definition is

An object that acts as a Gateway to a database table. One instance handles all the rows in the table.

which 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:

  • http://framework.zend.com/manual/en/zend.db.table.html


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.

<?php
public function loginvalidation($username,$pwd)
{
  $s = $this->select();
  $s->where('UserNmae = ?',$username)
  $s->where('UserPW = ?',$pwd);

  $rowset = $this->fetchall($s);
  if(count($rowset) == 1)
  {
   return $row->current()->toArray();
  } else {
   return "Invalid"
  }
}

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.

<?php
public function loginvalidation($username,$pwd)
{
  $rowset = $this->getAdapter()->query('UserName = \'' . $username . '\'and UserPW = \''. $pwd . '\'');
  if(count($rowset) == 1)
  {
   return $row->current()->toArray();
  } else {
   return "Invalid"
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号