I have a problem, here is the code ...
Code: Select all
require_once('dbconnect.php');
include 'header.php';
class Market {
var $submit;
function __construct() {
$this->submit = $_POST['Submit'];
}Can anyone tell me how to do this?
Thanks
Moderator: General Moderators
Code: Select all
require_once('dbconnect.php');
include 'header.php';
class Market {
var $submit;
function __construct() {
$this->submit = $_POST['Submit'];
}Code: Select all
if (!empty($_POST['submit'])) {
$this->submit = $_POST['Submit'];
} else {
$this->submit = ''; // default value
}Code: Select all
<?php
class Market
{
var $submit;
function __construct()
{
$this->submit = $_POST['Submit'];
}
}
$tst = new Market();
print_r($tst->submit);
?>Code: Select all
<?php
class Request
{
// {{{ properties
/**
* Array with request data. e.g $_REQUEST
*
* @var array
*/
private $fields;
static private $instance = null;
// }}} properties
// {{{ __construct()
/**
* Singleton pattern
*
*/
private function __construct()
{
$this->init();
}
private function __clone() {}
// }}} __construct()
static public function getInstance()
{
if (! self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Here could implement init() to know cli params.
*
*/
private function init()
{
if (isset($_SERVER['REQUEST_METHOD'])) {
$this->fields = $_REQUEST;
$r = array();
foreach ($this->fields as $fieldName=>$fieldValue) {
$r[$fieldName] = trim($fieldValue);
}
$this->fields = $r;
}
}
// {{{ get()
public function get($fieldName = null,$defaultValue = '')
{
if (is_null($fieldName)) return $this->fields;
if (isset($this->fields[$fieldName])) {
return $this->fields[$fieldName];
}
return $defaultValue;
}
// }}} get()
// {{{ set()
public function set($fieldName,$value)
{
$this->fields[$fieldName] = $value;
}
// }}} set()
}
// }}} Request
$request = Request::getInstance();
/*@var $request Request */
$request->get('Submit');//get var as is.
?>