MVCのように特定のビューに接続するコントローラーを実装したいと思います。PHPで提供されているフレームワークを使用していません。
だから、私はそれを行うためのいくつかのガイドとアドバイスが必要です。
私はいくつかのコントローラーとビューを持っています。私の見解では、データのみを出力したいと思います。私の懸念は、コントローラーの関数(のような)が、ユーザーが入力しcreate()
たすべてのデータを取得し、コントローラーの関数で新しいモデルを作成する方法です。$_POST['params']
views/create.php
create()
それで、今、私はこのようにすることを考えています、私は私のコントローラーフォルダーにMyViewsクラスを作成します。目的は、特定のビューをロードし、すべての$_POST
パラメーターをオブジェクトに取り込むことです。次に、Users_controllersなどのすべてのコントローラーがMyViewsを作成します。、などのUsers_controllersの関数では、MyViewsの関数を使用して特定のビューをロードし、オブジェクトをロードする場合があります。create()
destroy()
ビューをロードするソースを見つけました
<?php
class MyView {
protected $template_dir = 'templates/';
protected $vars = array();
public function __construct($template_dir = null) {
if ($template_dir !== null) {
// Check here whether this directory really exists
$this->template_dir = $template_dir;
}
}
public function render($template_file) {
if (file_exists($this->template_dir.$template_file)) {
include $this->template_dir.$template_file;
} else {
throw new Exception('no template file ' . $template_file . ' present in directory ' . $this->template_dir);
}
}
public function __set($name, $value) {
$this->vars[$name] = $value;
}
public function __get($name) {
return $this->vars[$name];
}
} ?>
うーん、どうすれば_POSTパラメータを検出できるかわかりません
if(isset($_POST['Post']))
{
$model->attributes=$_POST['Post'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
これは私が観察したYiiフレームワークです。特定のビューをロードしたかどうかに関係なく、パラメータを検出するにはどうすればよいですか$_POST
。$_GET
タスクをアーカイブするためのガイダンスやアドバイスはありますか?