Zend Framework - 非对象上的 select()

发布于 2024-12-17 12:10:52 字数 4115 浏览 1 评论 0原文

编辑 23/11 :解决方案成立...我在构造函数中写了 $_db 而不是 $this->_db !真是个菜鸟!

我尝试在我的 ZF 应用程序中创建一个新模型。 我收到错误:

致命错误:在第 86 行的 [...]/models/TrackingPageMapper.php 中的非对象上调用成员函数 select()

我是 ZF 的新用户我想我忘记了什么。

这是我的班级代码:

/**
 * TrackingPageMapper
 * @author Raphaël Deschler - [email protected]
 * @version 0.1
 */

class Default_Model_TrackingPageMapper
{
    private $_db;

/**
 * __construct
 */
public function __construct() 
{
    $_db = Zend_Db_Table::getDefaultAdapter();
}

#-----[Public Section]

/**
 * addView()
 * @param EtId, etablissement id
 * 
 * Check :
 * 1) If this is the first click of the day for this IP on this page
 * 2) If this is the first click of the month for this IP
 * 3) Save or not
 * 
 * @return void
 * 
 */
public function addView($EtId)
{
    $today = getDate();
    $ip = $this->getRealIp();
    
    //Check If is the IP exists
    $this->ipExists($ip, $EtId);
    
    //print_r($today);
    
    
    
    
}

#-----[Private Section]

/**
 * getRealIp()
 * @return varchar(15)
 * 
 */
private function getRealIp()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    {
      $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip = $_SERVER['REMOTE_ADDR'];
    }
    
    return $ip;
}

/**
 * ipExists()
 * @param Ip address
 * @param EtId, etablissement id
 * 
 * @return false if ip !exists
 * @return array of ip infos if exists
 * 
 */
public function ipExists($Ip, $EtId = null)
{
    $myQuery = $this->_db->select()
                         ->from('tracking_ip', 'idtracking_ip')
                         ->where('ip = ?',$Ip);
    
    $result = $this->_db->fetchAll($myQuery);
    
    print_r($result);
}
}

我这样称呼这个模型:

$oTrack = new Default_Model_TrackingPageMapper;
$oTrack->addView($Id);

任何人都可以帮助我吗?

感谢您的支持,

编辑

var_dump($_db);

object(Zend_Db_Adapter_Pdo_Mysql)#76 (12) {
  ["_pdoType":protected]=>
  string(5) "mysql"
  ["_numericDataTypes":protected]=>
  array(16) {
    [0]=>
    int(0)
    [1]=>
    int(1)
    [2]=>
    int(2)
    ["INT"]=>
    int(0)
    ["INTEGER"]=>
    int(0)
    ["MEDIUMINT"]=>
    int(0)
    ["SMALLINT"]=>
    int(0)
    ["TINYINT"]=>
    int(0)
    ["BIGINT"]=>
    int(1)
    ["SERIAL"]=>
    int(1)
    ["DEC"]=>
    int(2)
    ["DECIMAL"]=>
    int(2)
    ["DOUBLE"]=>
    int(2)
    ["DOUBLE PRECISION"]=>
    int(2)
    ["FIXED"]=>
    int(2)
    ["FLOAT"]=>
    int(2)
  }
  ["_defaultStmtClass":protected]=>
  string(21) "Zend_Db_Statement_Pdo"
  ["_config":protected]=>
  array(7) {
    ["username"]=>
    string(4) "riad"
    ["password"]=>
    string(7) "xxxxxx"
    ["dbname"]=>
    string(8) "riad_dev"
    ["charset"]=>
    string(4) "utf8"
    ["driver_options"]=>
    array(1) {
      [1002]=>
      string(14) "SET NAMES utf8"
    }
    ["persistent"]=>
    bool(false)
    ["options"]=>
    array(3) {
      ["caseFolding"]=>
      int(0)
      ["autoQuoteIdentifiers"]=>
      bool(true)
      ["fetchMode"]=>
      int(2)
    }
  }
  ["_fetchMode":protected]=>
  int(2)
  ["_profiler":protected]=>
  object(Zend_Db_Profiler)#74 (4) {
     ["_queryProfiles":protected]=>
     array(0) {
     }
    ["_enabled":protected]=>
    bool(false)
    ["_filterElapsedSecs":protected]=>
    NULL
    ["_filterTypes":protected]=>
    NULL
  }
  ["_defaultProfilerClass":protected]=>
  string(16) "Zend_Db_Profiler"
  ["_connection":protected]=>
  NULL
  ["_caseFolding":protected]=>
  int(0)
  ["_autoQuoteIdentifiers":protected]=>
  bool(true)
  ["_allowSerialization":protected]=>
  bool(true)
  ["_autoReconnectOnUnserialize":protected]=>
  bool(false)
   }

EDIT 23/11 : Solution founded ... I wrote $_db instead $this->_db in the constructor ! WHAT A NOOB !

I try to create a new model in my ZF application.
I get an error :

Fatal error: Call to a member function select() on a non-object in [...]/models/TrackingPageMapper.php on line 86

I'm new user of ZF and I think I forget anything.

Here is my class code :

/**
 * TrackingPageMapper
 * @author Raphaël Deschler - [email protected]
 * @version 0.1
 */

class Default_Model_TrackingPageMapper
{
    private $_db;

/**
 * __construct
 */
public function __construct() 
{
    $_db = Zend_Db_Table::getDefaultAdapter();
}

#-----[Public Section]

/**
 * addView()
 * @param EtId, etablissement id
 * 
 * Check :
 * 1) If this is the first click of the day for this IP on this page
 * 2) If this is the first click of the month for this IP
 * 3) Save or not
 * 
 * @return void
 * 
 */
public function addView($EtId)
{
    $today = getDate();
    $ip = $this->getRealIp();
    
    //Check If is the IP exists
    $this->ipExists($ip, $EtId);
    
    //print_r($today);
    
    
    
    
}

#-----[Private Section]

/**
 * getRealIp()
 * @return varchar(15)
 * 
 */
private function getRealIp()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    {
      $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip = $_SERVER['REMOTE_ADDR'];
    }
    
    return $ip;
}

/**
 * ipExists()
 * @param Ip address
 * @param EtId, etablissement id
 * 
 * @return false if ip !exists
 * @return array of ip infos if exists
 * 
 */
public function ipExists($Ip, $EtId = null)
{
    $myQuery = $this->_db->select()
                         ->from('tracking_ip', 'idtracking_ip')
                         ->where('ip = ?',$Ip);
    
    $result = $this->_db->fetchAll($myQuery);
    
    print_r($result);
}
}

And I call this Model like that :

$oTrack = new Default_Model_TrackingPageMapper;
$oTrack->addView($Id);

Anyone can help me ?

Thanks for your support comming,

Edit

var_dump($_db);

object(Zend_Db_Adapter_Pdo_Mysql)#76 (12) {
  ["_pdoType":protected]=>
  string(5) "mysql"
  ["_numericDataTypes":protected]=>
  array(16) {
    [0]=>
    int(0)
    [1]=>
    int(1)
    [2]=>
    int(2)
    ["INT"]=>
    int(0)
    ["INTEGER"]=>
    int(0)
    ["MEDIUMINT"]=>
    int(0)
    ["SMALLINT"]=>
    int(0)
    ["TINYINT"]=>
    int(0)
    ["BIGINT"]=>
    int(1)
    ["SERIAL"]=>
    int(1)
    ["DEC"]=>
    int(2)
    ["DECIMAL"]=>
    int(2)
    ["DOUBLE"]=>
    int(2)
    ["DOUBLE PRECISION"]=>
    int(2)
    ["FIXED"]=>
    int(2)
    ["FLOAT"]=>
    int(2)
  }
  ["_defaultStmtClass":protected]=>
  string(21) "Zend_Db_Statement_Pdo"
  ["_config":protected]=>
  array(7) {
    ["username"]=>
    string(4) "riad"
    ["password"]=>
    string(7) "xxxxxx"
    ["dbname"]=>
    string(8) "riad_dev"
    ["charset"]=>
    string(4) "utf8"
    ["driver_options"]=>
    array(1) {
      [1002]=>
      string(14) "SET NAMES utf8"
    }
    ["persistent"]=>
    bool(false)
    ["options"]=>
    array(3) {
      ["caseFolding"]=>
      int(0)
      ["autoQuoteIdentifiers"]=>
      bool(true)
      ["fetchMode"]=>
      int(2)
    }
  }
  ["_fetchMode":protected]=>
  int(2)
  ["_profiler":protected]=>
  object(Zend_Db_Profiler)#74 (4) {
     ["_queryProfiles":protected]=>
     array(0) {
     }
    ["_enabled":protected]=>
    bool(false)
    ["_filterElapsedSecs":protected]=>
    NULL
    ["_filterTypes":protected]=>
    NULL
  }
  ["_defaultProfilerClass":protected]=>
  string(16) "Zend_Db_Profiler"
  ["_connection":protected]=>
  NULL
  ["_caseFolding":protected]=>
  int(0)
  ["_autoQuoteIdentifiers":protected]=>
  bool(true)
  ["_allowSerialization":protected]=>
  bool(true)
  ["_autoReconnectOnUnserialize":protected]=>
  bool(false)
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初与友歌 2024-12-24 12:10:52

找到解决方案...我在构造函数中写了 $_db 而不是 $this->_db

Solution found ... I wrote $_db instead $this->_db in the constructor

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文