dongyi2159 2013-08-17 01:26
浏览 19

从类中获取(错误)消息

If I have a model login (class Login) that when posted to from a login.php (the form) operates as any other login script. If an error occurs it dumps the error into a public function within the class.

public function displayMessageEntry($error, $exit = NULL) {

    if( !empty($error) ) :

        return $error;

    endif;

}

via $this->error ? self::displayMessageEntry($this->error, false) : self::displayMessageEntry($this->msg, false);

This works all fine when I was using simple templates as I would just echo it out and it would appear in the body portion when I had a head, body, and footer includes, however my design has gotten more complex, and I cannot seem to figure out how to access the $error data (if any), via something like this: <?php echo isset($err) ? $err : NULL; ?> called on the login page itself. Under previous login scripts I used I would just have the procedural code under an isset($_POST) and then any errors or messages would be added to an array and parsed the aforementioned way. Is there any way of doing this given the layout I mentioned?

  • 写回答

1条回答 默认 最新

  • dsgtew3241 2013-08-17 01:53
    关注

    Got it. Was as simple as <?php echo isset($login->error) ? $login->error : ''; ?> and modifying the display function to:

    public function displayMessageEntry($error, $exit = NULL) {
    
        if( !empty($error) ) :
    
            $this->error;
    
        endif;
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题