简体   繁体   English

在Octobercms页面中运行外部PHP脚本

[英]Running an external PHP script within a page of Octobercms

to speed up the creation of a CRUD interface in the frontend I am trying to use an external tool/program called PDOCrud within octobercms (PHP 7.2). 为了加快前端中CRUD接口的创建速度,我尝试在octobercms(PHP 7.2)中使用一个称为PDOCrud的外部工具/程序。 PDOCrud does perfectly its job when works alone but I am facing problem to integrate it in Octobercms (I hope it can be integrated). 当单独工作时,PDOCrud可以很好地完成其工作,但是我在将它集成到Octobercms时遇到了问题(我希望它可以被集成)。

This is the normal code of PDOCrud to render a crud interface: 这是PDOCrud呈现Crud接口的常规代码:

 require_once base_path('script/pdocrud.php'); 
 $pdocrud = new PDOCrud();
 echo $pdocrud->dbTable("tablename")->render(); 

This is how I included it in a normal page 这就是我在普通页面中添加它的方式

title = "Make tournament"
url = "/make-tournament"
layout = "Default"
description = "some description"
is_hidden = 0
==
<?php
function onstart() { 
  require_once base_path('script/pdocrud.php'); 
  $this['crud'] = new class {
        public function foo() {
            $pdocrud = new PDOCrud();
            return $pdocrud->dbTable("tablename")->render(); 
            // return phpinfo();
        }
    };
}
?>
==
<h1>Make crud</h1>
{{ crud.foo()|raw }}

The form appears. 出现表格。 But the buttons for crud operations does not perform any actions. 但是,用于Crud操作的按钮不执行任何操作。 Perhaps the session of octobercms collide with that of the external code, or jquery that it is loaded perhaps two times. octobercms的会话可能与外部代码的会话冲突,或者jquery可能两次加载了该会话。 Does anybody tried a similar approach and solved the problem? 是否有人尝试过类似的方法并解决了问题?

EDIT: I tried the suggestions but it did not work for me, maybe I missed something. 编辑:我尝试了建议,但对我没有用,也许我错过了一些东西。 Just few hours ago the author of the external program made un upgrade and my previous code worked perfectly. 就在几个小时前,外部程序的作者进行了升级,而我之前的代码运行良好。 I am aware of not using properly the framework but I need a workaround to face a deadline. 我知道没有正确使用框架,但是我需要一个变通方法来面对最后期限。 Thanks to all of you! 感谢大家!

Using PDOCrud for this purpose is overlooking a significant amount of the features that are built into OctoberCMS. 为此目的使用PDOCrud会忽略OctoberCMS内置的大量功能。 It would be very simple to create a custom plugin for yourself and integrate the incredibly powerful and easy to use backend forms in a component to use on your frontend. 为自己创建一个自定义插件,并将非常强大且易于使用的后端表单集成到要在前端使用的组件中,将非常简单。

See 看到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM