ggf*_*fan 6 php model-view-controller frameworks
自从我拿起一本PHP书并开始用PHP编写代码以来已经有5个月了.起初,我创建了我的所有网站,没有任何组织计划或MVC.我很快就发现这很痛苦.然后我开始阅读有关如何分离php和html的stackoverflow,这就是我以后一直在做的事情.
Ex:
profile.php <--this file is HTML,css. I just echo the functions here.
profile_functions.php <--this file is mostly PHP. has the functions.
Run Code Online (Sandbox Code Playgroud)
这就是我到目前为止分离所有编码的方式,现在我觉得我应该继续开始MVC.但问题是,我以前从未使用过课程并且习惯了它们.而且由于MVC(例如cakephp和codeigniter)都是类,所以这不是好事.
我的问题:是否有任何好的书籍/网站/文章教你如何在MVC中编码?我正在寻找初学者初学者书:)我刚刚开始阅读codeigniter manuel,我想我会用它.
编辑:是否有可能在不使用cake,codeigniter等的情况下为您的编码创建MVC组织结构?基本上只是将profile.php分成三个不同的文件(视图,控制器,模型)
回答你的问题
是否可以在不使用 cake、codeigniter 等的情况下为您的编码提供 MVC 组织结构?基本上只是将 profile.php 分成 3 个不同的文件(视图、控制器、模型)
绝对地...
第一个文件 profile.php (视图,浏览器点击的内容)
<?php
include( 'controllers/UsersController.php' );
$controller = new UsersController();
$controller->profile();
$pageData = $controller->data;
?>
Run Code Online (Sandbox Code Playgroud)
控制器
<?php
include 'models/UsersModel.php';
class UsersController{
public $data;
public $model;
public function __construct(){
$this->model = new UserModel();
}
public function profile(){
$this->data = $this->model->findUser();
}
}
Run Code Online (Sandbox Code Playgroud)
该模型
<?php
class UsersModel{
public function __constuct(){
// connect to your db or whatever you need to do
}
public function findUser(){
return mysql_query( "SELECT * FROM users WHERE users.id = 2 LIMIT 1" );
}
}
Run Code Online (Sandbox Code Playgroud)