如何将独立的PHP文件转换为Magento的MVC [英] How to convert standalone PHP files to Magento's MVC

查看:59
本文介绍了如何将独立的PHP文件转换为Magento的MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个任务将独立的PHP文件转换为Magento的MVC.这些PHP文件是由另一个开发人员创建的. PHP文件中的代码访问数据库,将结果转换为JSONP格式,并将其转发给前端开发人员.

I have a task to convert the standalone PHP files to Magento's MVC. These PHP files were created by another developer. The code in the PHP file accesses the database, converts the result into JSONP format and forward it to the frontend developer.

我对Magento的MVC不了解.此转换任务是否类似于Magento文件夹中app/code/core/Mage中的模块?我怎样才能做到这一点? magento MVC与PHP MVC是否相同?

I don't have any knowledge of Magento's MVC. Is this task of conversion similar to the modules in the app/code/core/Mage in the Magento folder?? How can I do this? Is the magento MVC the same as the PHP MVC?

我包括了我需要转换为Magento MVC的php文件.因此,这将使您更容易理解..

I am including the php file that I need to convert to Magento MVC. So it will be easier for you to understand..

<?php header('content-type: application/json; charset=utf-8');
$link = mysqli_connect("localhost", "db_username", "password", "db_dbname");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$pid = $_REQUEST['prodid'];

/* Select queries return a resultset */

$result = mysqli_query($link, "SELECT round(rating_summary / 20) AS search_rating FROM review_entity_summary where store_id = 1 and entity_pk_value=" . $pid);

// printf("Select returned %d rows.\n" . "<br>\n", mysqli_num_rows($result)) . "<br>\n";
//$string = $_REQUEST['varname'];
    $rows = array();
  /*  while ($row = $result->fetch_row()) {
                printf("%s\n", $row[0]);
            }*/
//while($r = mysql_fetch_assoc($result)) {
while ($r = mysqli_fetch_assoc($result)) {
    $rows = $r;
//print_r ($rows) . "<br>\n";
}
$json_data = json_encode($rows);
print_r ($json_data);
    /* free result set */
   // mysqli_free_result($result)

mysqli_close($link);
?>

那么如何将这个文件转换为Magento的MVC样式?是否需要将此文件转换为magento MVC?

So how can I convert this file to Magento's MVC style?? IS this necessary to convert this file to magento MVC?

推荐答案

我认为他们要您做的是转换看起来像这样的代码

I think what they are asking you to do, is to convert code that look like

require_once 'path/to/magento'. "/Mage.php";
umask(0);
Mage::app("default");
....

进入Magento MVC(模块)

In to Magento MVC (module)

\app\code\local\MyNamespace

如果您不熟悉OOP,请在此处查看: http ://www.php.net/manual/zh-CN/language.namespaces.rationale.php

If you're new to OOP, take a look here: http://www.php.net/manual/en/language.namespaces.rationale.php

\app\code\local\MyNamespace\Appname

新的自定义模块的名称-尝试至少保留首字母大写,否则将被Magento的理解所困扰

Name of new custom module - try to keep at least first letter capital, or there WILL BE truble with Magento's understanding

\app\code\local\MyNamespace\Appname\Block

在经典的MVC体系结构中,这表示MVC的View部分

In classic MVC architecture, this represents View part of MVC

\app\code\local\MyNamespace\Appname\controllers

这相当容易理解,如果没有的话,请尽情玩乐:

This is fairly easy to understand, if not, have fun: http://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller

\app\code\local\MyNamespace\Appname \etc

包含Magento MVC架构中最重要的部分-将所有内容连接在一起的xml字段

Contains the most significant part in Magento's MVC architecture - the xml field that will connect all things together

\app\code\local\MyNamespace\Appname\Helper

适用于包含可重复例程或简单程序方法的文件

Intended for files that contain repeatable routines or simple procedural methods

 \app\code\local\MyNamespace\Appname\Model

与控制器相同,请看上面的链接

Same thing as for controller, take a look at the link above

 \app\code\local\MyNamespace\Appname\sql

这是一件很有趣的事情,以了解它的用途,它是定义自定义数据库表并处理对扩展的任何升级.

This was interesting thing to find out what's it for, it's to define custom database tables and process any upgrades to your extension.

 \etc\modules

包含Magento中包含的所有模块-这是我们模块真正开始的地方

Contains all Modules included in Magento - here's where it all really begins for our module

请参见 http://inchoo.net/电子商务/magento/基本文件夹结构-新的magento模块/

这篇关于如何将独立的PHP文件转换为Magento的MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆