English 中文(简体)
在PHP中执行控制人员的最佳方式是什么?
原标题:What is the best way to implement a controller in PHP?

我认为,在我所介绍的最近两个网站中,我采用了一种MVC式控制器。

我使用了<代码>mod_rewrite,通过索引.php发送了所有材料,因此,url变成了争.。

它发挥了作用,但我不禁要问,它是否只是表面上的黑客,还是只是一种可接受的做事方式。 是否有更好的办法? 我不想有一个框架,但我要学习自己这样做。

最佳回答

了解我世界上最小的框架。

<?php
$g=$_GET;$c=@$g[ c ]?$g[ c ]: Home ;
if(!@include"c/$c.php")die( fail );
$m=method_exists($c,$m=@$g[ m ])?$m: index ;
$o=new$c();$o->$m($g);

指数.php和你的控制器是Blog.php。

class Blog {

    function index()
    {
        echo "Hello world";
    }

    function otherpage()
    {
        echo "ZOMG!";
    }

主要是作为oke子干的,因为我想要制定一个可以符合tw的框架,但基本逻辑是存在的;

问题回答

通过单一入境点(例如指数)处理所有事项。 营地不是MVC,而是“前主计长模式”。 但是,这与科索沃移民委员会完全吻合。 See my related answer here

除此之外,为什么不检查周围的一些框架,以了解它们如何这样做。 这并不意味着你们必须使用这些工具,只是看自己的准则,并适应自己的框架。

这为我完成这项任务创造了条件。 我随后创建了一个派遣表,该表是根据控制人员即时携带和发送的URL。

如何学习如何做到,但仍使用框架? 要么看看看像书状或像Wordpress、Jommla! 等等,你会发现,他们都使用 mo改板把东西 off掉。

大多数PHP框架都利用 mo泥实现同样的目标,这是压制指数的唯一途径。

我这样说,你走了正确的道路。

你使用的这一方法被称为FrontController patterns,并且也用于这些框架,以便与MVC模式保持一致。

如果你仔细考虑某项建议,我就建议你通过每一页控制器提出每一项请求,并延长基数控制器,因为每个网站都有一些基底数据结构,你可能需要在每一页使用,例如模板和届会控制。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签