我只是掌握了MVC框架,我常常想知道模型中应该有多少代码.我倾向于有一个数据访问类,其方法如下:
public function CheckUsername($connection, $username)
{
try
{
$data = array();
$data['Username'] = $username;
//// SQL
$sql = "SELECT Username FROM" . $this->usersTableName . " WHERE Username = :Username";
//// Execute statement
return $this->ExecuteObject($connection, $sql, $data);
}
catch(Exception $e)
{
throw $e;
}
}
Run Code Online (Sandbox Code Playgroud)
我的模型往往是映射到数据库表的实体类.
模型对象是否应具有所有数据库映射属性以及上面的代码,或者可以将实际上数据库工作的代码分开吗?
我最终会有四层吗?
$ this-> render和$ this-> redirect之间有什么区别.有没有办法可以使用$ this-> render传递参数,就像我使用$ this-> redirect一样
return $this->render('MedicineUserBundle:User:home.html.twig', array(
'info' => $all,));
Run Code Online (Sandbox Code Playgroud)
我可以这样做: -
return $this->redirect($this->generateUrl('MedicineUserBundle_login', array(
'info' => $all,)));
Run Code Online (Sandbox Code Playgroud)
或者有没有其他方法我可以使用$ this-> redirect传递值到我的模板twig文件.
还有一个问题我如何更改网址$this->redirect,例如,如果我不必将任何值传递给我的模板文件,我可以像上面提到的那样,渲染会将我带到像localhost/myproject/home这样的页面,但$->this->redirect会执行控制器但是url会像localhost/myproject /一样.无论如何我可以使用重定向重定向到另一个网址