Advice/suggestions for my first project PHP Classes

Posted by Philip on Stack Overflow See other posts from Stack Overflow or by Philip
Published on 2010-05-13T13:07:05Z Indexed on 2010/05/13 18:14 UTC
Read the original article Hit count: 274

Filed under:
|
|
|

Hi guys, Any advice is welcome! I have a very limited understanding of php classes but below is my starting point for the route I would like to take. The code is a reflection of what I see in my head and how I would like to go about business. Does my code even look ok, or am I way off base?

What are your thoughts, how would you go about achieving such a task as form->validate->insertquery->sendmail->return messages and errors?

Please try and keep your answers simple enough for me to digest as for me its about understanding whats going on and not just a copy/paste job.

Kindest regards, Phil.

Note: This is a base structure only, no complete code added.

<?php
//=======================================
    //class.logging.php
//========================================
    class logging
    {

        public $data = array();
        public $errors = array();



        function __construct()
        {
            array_pop($_POST);
            $this->data =($this->_logging)? is_isset(filterStr($_POST) : '';

            foreach($this->data as $key=> $value)
            {
                $this->data[$key] = $value; 
            }
            //print_r($this->data); de-bugging
        }

        public function is_isset($str)
        {
            if(isset($str)) ? true: false;
        }

        public function filterStr($str)
        {
            return preg_match(do somthing, $str);
        }

        public function validate_post()
        {
            try
            {
                if(!is_numeric($data['cardID'])) ? throw new Exception('CardID must be numeric!') : continue;   
            }
            catch (Exception $e)
            {

                return $errors = $e->getCode();
            }
        }

        public function showErrors()
        {
            foreach($errors as $error => $err)
            {
                print('<div class="notok"></div><br />');
            }
        }

        public function insertQ()
        {
            $query = "";
        }

    }


//=======================================
    //Usercp.php
//========================================
if(isset($_GET['mode']))
     {
     $mode = $_GET['mode'];
     }
     else
     {
     $mode = 'usercp';
     }


     switch($mode)
    {
        case 'usercp':
        echo 'Welcome to the User Control Panel';
        break;

        case 'logging':
            require_once 'class.logging.php';
            $logger = new logging();

            if(isset($_POST['submit'])
            {
                if($logger->validate_post === true)
                {
                    $logger->insertQ();
                    require_once '/scripts/PHPMailer/class.phpmailer.php';
                    $mailer = new PHPMailer();
                    $mailer->PHPMailer();
                }
                else
                {
                    echo ''.$logger->showErrors.''; 
                }
            }
            else
            {
                echo 
                    '
                    <form action="'.$_SERVER['PHP_SELF'].'?mode=logging" method="post">

                    </form>
                    ';  
            }
        break;

        case 'user_logout':
        // do somthing
        break;

        case 'user_settings':
        // do somthing
        break;






?>

© Stack Overflow or respective owner

Related posts about advice

Related posts about php