帮助理解mvc php
好的,昨天我开了一个关于何时使用 mvc 的主题,
今天我将学习 MVC 框架如何工作,检查一些示例,如 CI、CAKE 等
在 .htaccess 上我发现了这个
重写引擎开启 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/?url=$1 [QSA,L]
好的,当我们输入 http://localhost/mymvc/something1/something2/something3/somethingetc
我们得到一个 $_GET['url'] =
string 'something1/something2/something3/somethingetc' (length=45)
2.所以我建议 something1 将是类,something2 必须是函数和某些东西我不太确定,框架如何正确加载类?函数?
class Blog extends Controller {
function index()
{
echo 'Hello World!';
}
function stack()
{
echo 'Hello Stack!';
}
}
3.好吧,我发现每个框架首先加载配置文件,然后加载一个前端控制器,这是一个前端控制器(在ci上)看起来,我假设他们这样做?
- 扩展课程?
- 他们知道班级的名称吗?然后 require_oncecontroller.nameclass.php
- 然后他们以某种方式搜索函数? (他们是怎么做到的?)
- 接下来他们会查找默认函数(函数索引)然后加载它?
- 如果有客户端调用 url /Blog/stack,它只会加载 Stack 函数,我也不知道它是如何工作的。
- 如果我们放置 $this->loadview('something') ,那么我假设它们调用函数 loadview (位于 Controller 类内部,并按名称要求它们,例如 require_once Something.php
也许有第二部分:|,
非常感谢
亚当·拉马丹。
ok yesterday i open a thread about when to use mvc,
today I'm about to learn how MVC frameworks work, examining some examples like CI, CAKE, etc
on the .htaccess i found this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/?url=$1 [QSA,L]
ok so when we type http://localhost/mymvc/something1/something2/something3/somethingetc
we got an $_GET['url'] =
string 'something1/something2/something3/somethingetc' (length=45)
2.so I suggest the something1 will be the class, something2 must be the function and something3 im not quite sure, how does exectly framework loads the class ?, functions ?
class Blog extends Controller {
function index()
{
echo 'Hello World!';
}
function stack()
{
echo 'Hello Stack!';
}
}
3.ok so , i found that every framework first loads the config files, then loads a front-controller this is a front-controller ( on ci ) looks, i assume that they do like this ?
- extends the class ?
- they get the name of the class ? then require_once controller.nameclass.php
- then they somehow search for functions ? ( how do they do that ? )
- next they look for the default function ( function index ) then loads it ?
- if there is a client call the url /Blog/stack it loads just the Stack function, i dont >know how that work either .
- if we put $this->loadview('something') so i assume that they call the function loadview ( that is inside the Controller class and require them by the name, like require_once something.php
Maybe there is a part two of this :|,
Thanks a lot.
Adam Ramadhan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
call_user_func
或类似的东西在框架的核心功能执行后调用该功能。在许多情况下,控制器类会继承基类来实现此功能。
这并不能真正给你太多。如果您学习如何使用框架,而不是它如何工作,那么您在使用框架时会更幸运。
如果您参加纯 MVC 课程(未链接到任何框架),或者如果您很着急,请尝试 这个。
call_user_func
or something similar to call the functionality after the framework's core functionality has executed.Controller classes in many cases inherit a base class, for this functionality.
This doesn't really give you much. You'd have better luck with the frameworks if you learn how to work with it, not how it works.
It might help if you take a course of pure MVC (not linked to any framework), or if you're in a hurry, try this.
这是一个非常简单的示例: http://r.je/mvc-in-php.html
Here's a very simplified example: http://r.je/mvc-in-php.html