Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我应该在哪里使用MVC方法处理变量?_Php_Templates - Fatal编程技术网

Php 我应该在哪里使用MVC方法处理变量?

Php 我应该在哪里使用MVC方法处理变量?,php,templates,Php,Templates,F.e.我得到一个变量,MVC应用程序必须根据变量显示稍微不同的JS。我应该在何处将此变量处理到视图或控制器中? MVC方法论是怎么说的 $max_orders_count可能大于0,如果其为无穷大,则=0 第一条路 Controller: if ($max_orders_count === 0) { $this->view('view1.php'); } elseif ($max_orders_count > 0) { $this->view('view2.php'); }

F.e.我得到一个变量,MVC应用程序必须根据变量显示稍微不同的JS。我应该在何处将此变量处理到视图或控制器中? MVC方法论是怎么说的

$max_orders_count可能大于0,如果其为无穷大,则=0

第一条路

Controller:

if ($max_orders_count === 0) {
$this->view('view1.php');
} elseif ($max_orders_count > 0) {
$this->view('view2.php');
}
Controller:

$this->view('view.php', array('max_orders_count' => $max_orders_count));

View:

<?if ($max_orders_count === 0) {?>
     <script>JS1</script>
<?}?>

<?if ($max_orders_count > 0) {?>
     <script>JS2</script>
<?}?>
第二种方式

Controller:

if ($max_orders_count === 0) {
$this->view('view1.php');
} elseif ($max_orders_count > 0) {
$this->view('view2.php');
}
Controller:

$this->view('view.php', array('max_orders_count' => $max_orders_count));

View:

<?if ($max_orders_count === 0) {?>
     <script>JS1</script>
<?}?>

<?if ($max_orders_count > 0) {?>
     <script>JS2</script>
<?}?>
控制器:
$this->view('view.php',array('max\u orders\u count'=>$max\u orders\u count));
视图:
JS1
JS2

CodeIgniter使用一个可选模型的典型web模式、一个包含代码的HTML模板(一个PHP页面,因为它是PHP)以及一个在模板和模型之间进行对话的类

CodeIgniter将PHP文件称为“视图”(一些框架,特别是PHP之外的框架,称其为模板),并将中介类称为“控制器”(一些框架称其为“视图”)

这意味着模式CodeIgniter调用MVC与传统的MVC框架关系不大,后者是事件驱动的,主要用于GUI应用程序

这也意味着你的问题的答案是:你可以随意处理变量


通常不赞成在模板中包含代码。任何复杂的代码都应该放在W控制器中。但这只是做一个条件检查,可以放在模板中。

请给出一个更详细的示例“处理”?用什么方法处理?你真的在使用MVC吗?大多数声称MVC的web框架都不是,而是使用model/view/template,它通常被称为MVC,但实际上一点也不像MVC。你在用什么框架?吉姆,我用了。雷杰布罗先生,MVC和MTC(模板)有什么区别?@user1312750它们基本上完全不同。您使用的是什么框架?更多说明: