Implemented the following design:
Form with action = "/?page=pages&controller=add"
where page
is the name of the class, controller
is the name of the method to which you need to transfer data from the form.
public function add() { if (!empty($_POST)) { echo "<pre>"; print_r($_POST); echo "</pre>"; } else { echo "ERROR!!!"; } }
However, when sending a request returns ERROR!!!
.
If you look in Firebug, then after submitting the form, it is executed first.
POST constructor?page=pages&controller=add
(POST passed variables are displayed) with status 301 Moved Permanently, and then
GET ?page=pages&controller=add
which returns the answer ERROR!!!
.
Why can't I transfer data?
The form:
<form action="<?php echo BASEPATH;?>?page=pages&controller=add" method = "post"><br/> <input name ="title" placeholder ="Наименование"/><br/> <textarea name="description" placeholder="Описание"></textarea><br/> <textarea name="text" placeholder ="Текст"></textarea><br/> <textarea name="metakey" placeholder="META-Keywords"></textarea><br/> <textarea name="metadescr" placeholder ="META-Description"></textarea><br/> <input type = "submit" name = "add" value = "Сохранить"/> </form>
And here is the processing of the address bar parameters:
public function doCommand($uri, $type){ $controller = ''; $flag = FALSE; $dir = CMPDIR; $f = scandir($dir); foreach ($f as $file){ if(preg_match('/\.(php)/', $file)){ if($uri === substr($file, 0, -4)){ $flag = TRUE; $controller = CMPDIR.$file; break; } } } if($flag === FALSE){ $error['error'] = 'Страница <b>'.$_SERVER['HTTP_HOST'].'/'.implode('/',$uri).'</b> не существует'; $this->load('error404', $error); } else { include strtolower($controller); $cl = ucfirst($uri); $class = new $cl; $md = FALSE; $methreg = ''; $method = get_class_methods ( $class ); for ($i = 0; $i < count($method); $i ++){ if (strtolower($method[$i]) === strtolower($type)){ $md = TRUE; $methreg = $method[$i]; break; } } if ($md === TRUE){ return $class->$methreg(); } else { $error['error'] = 'Method не существует'; $this->load('error404', $error); } } }