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). PDOCrud does perfectly its job when works alone but I am facing problem to integrate it in Octobercms (I hope it can be integrated).
This is the normal code of PDOCrud to render a crud interface:
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. Perhaps the session of octobercms collide with that of the external code, or jquery that it is loaded perhaps two times.
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. 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
https://octobercms.com/plugin/rainlab-builder
https://octobercms.com/docs/backend/forms
https://octobercms.com/forum/post/using-backend-forms-in-frontend
Related
I've been trying to make a web crawler for the company i work for using behat combined with the mink extension. I did something similar in the past as well but the difference is that now the page i am trying to crawl through is build in angularjs.
This seems to cause an issue in my xpath selector which can not locate the elements i am requesting in the DOM.
To ensure i have the right xpath and double check it i also use the Xpath Helper from chrome (extension).
My function that i try to use is :
/**
* #Then I login
*/
public function login()
{
$page = $this->getSession()->getPage();
$username = $page->find('xpath', "//*[#id='inputEmail']/self::INPUT");
$password = $page->find('xpath', "//*[#id='inputPassword']/self::INPUT");
if ($username == null && $password == null) {
echo "nothing found";
}
else{
$username->setValue('username');
$password->setValue('password');
}
}
In my .feature file i am able to access the login page and check that i am there by "seeing" some text in the dom to verify it is working, but when i try to fill the values in the fields above i am getting an error.
I guess it is an angular issue by the way it creates the DOM elements which causes my xpath unable to locate the fields i need but i can't think of a work around for this one.
Of course to use a JS framework like Protractor can be a solution but i would like to stay in php as it is easier maintainable by the team i am working with.
Any ideas would be more than welcome.
Few ideas:
Use page objects to clean your code
Make sure the element is present before using it by waiting for it (find() can return null or element)
If you don't need UI use guzzle or use some headless driver
Try to create a wait condition specific for the angular if you are using the UI
Well, I am developing a plugin a and I need to display some stuff from my plugin when TYPO3 page load.
Is there some function how to hook action, like in WordPress when page loads than plugin will execute some controller method? Then this controller will produce some output a HTML, which I would like to dispaly in frontend page. Specially I would like display custom script in the head. So the script should be like this <head>...<script>my content</script>...</head>
Ok, what you probably want to do is to develop a so-called TYPO3 extension - that's what plugins/add-ons are called in TYPO3 (which is the term you will likely find google results for).
To get started fast you can try the TYPO3 extension builder (https://docs.typo3.org/typo3cms/extensions/extension_builder/) - which can generate a skeleton extension for you.
For more information you can also have a look at https://docs.typo3.org/typo3cms/CoreApiReference/latest/ExtensionArchitecture/Index.html which explains the concepts in far more detail.
Additional information is available in https://docs.typo3.org/typo3cms/ExtbaseFluidBook/Index.html
in TYPO3 there is something named plugins, but you should differ to the meaning in other context.
first TYPO3 is a CMS which content is structured in a hierarchical tree of pages. These pages are the basis for navigation. and each page contains individual contentelmenents (CE).
As Susi already told: add ons to TYPO3 are in general 'extensions' which could extend(!) the functinality of TYPO3 in different ways. one way is the definition of (TYPO3-)Plugins. These are special ContentElements which enable to show special information.
While normal CEs have all the information what to show in the record (e.g. Text & Image), plugins can be more flexible.
typical examples are: show a list of records OR one record in detail.
These Plugins can be controlled with typoscript or the plugin-CE could have additional fields to hold information what to display.
For detailed information how a plugin is defined consult the links given by Susi.
And be aware: for security reasons it is not possible to just execute a plain PHP file to echo any output. You need to register your plugin using the API, build your output as string and return the generated HTML as string to the calling function. For beginners the ExtensionBuilder will help you to generate a well formed extension which uses the API to register and output your data.
OK guys, thanks for your answers, but it was not very concrete. I found this solution, is not the best one, but it works! If anybody has better please share.
At first, you have to make a file for the class which will be called from the hook at location /your-plugin-name/Classes/class.tx_contenthook.php. Filename have to have this pattern class.tx_yourname.php Inside we will have a code with one method which will be called by the hook.
class tx_contenthook {
function displayContent(&$params, &$that){
//content of page from param
$content = $params['pObj']->content;
//your content
$inject = '4747474747';
// inject content on
$content = str_replace('</body>', $inject. '</body>', $content);
// save
$params['pObj']->content = $content;
}
}
And next, we have to call it on the hook. So Let's go to /your-plugin-name/ext_localconf.php and add there these two lines, which makes a magic and handles also caching.
// hook is called after caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'][] = 'EXT:' . $_EXTKEY . '/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
// hook is called before caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all'][] = 'EXT:'. $_EXTKEY .'/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
I hope this will help those who struggling with typo3.
I tried to implement this(http://web.archive.org/web/20080506155528/http://software.zuavra.net/inline-diff/) with my codeigntier framework but i could not able to implement it.
Anyone if you have implemented this with codeigniter framework then please help me.
Why i could not able to implement:
I run those files seperately(Not with framework) & it worked for me. but while keeping the same files( i.e inline_example.php content) in my COdeigniter controllers then it showed me too many errors like(shown in image) . Then i though this is out of my capacity to implement with codeignter. so i thought to ask here help
i have implemented this library in codeigniter.
To resolve that error you have to replace &new variable to new in all library files of inline diff.
for example :
inline_function.php
$diff = &new Text_Diff($hlines1, $hlines2);
$diff = new Text_Diff($hlines1, $hlines2);
and also change path in unified.php and diff.php
require_once(APPPATH.'libraries/Text/Diff/Renderer.php');
I'm working on a website I didn't make in the first place. It's made in 2 parts: the presentation website, and the OpenCart for the e-commerce part.
I need to use some functions of OpenCart, especially to have an access to the main tools (cart, price of the items in the cart ...) in the presentation website (not in the OpenCart template).
So I was wondering if there is any way I can load OpenCart and it's functions, without loading the template when I don't need it.
I know it may sound counter intuitive and may rise the page load time, but I don't have much choice, given the time I have to do this and the experience I lack with OpenCart.
EDIT:
Okay so I added this at the bottom of the index.php file of open cart:
if($_GET['module'] == 'website') {
include('website/index.php');
} else {
// Output
$response->output();
}
So in theory, OpenCart is loaded onto my website. But my guess in that output() calls the template AND it's controller, so I don't have access to the variables I need: $login, $text_login, $cart, $checkout ... the toolbox variables. I guess I need to call the controller, but I have no idea what controller is used for what variable... if you have an idea, I would be really thankful.
Thanks, Antoine
This will require quite a bit of work. You will essentially need to duplicate the index.php file in the catalog side and not run the final piece of the code, namely this
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));
// Router
if (isset($request->get['route'])) {
$action = new Action($request->get['route']);
} else {
$action = new Action('common/home');
}
// Dispatch
$controller->dispatch($action, new Action('error/not_found'));
and then you can set up your own actions to show code etc or load the necessary classes directly
I have a complex php application which I want to include in a typo3 page. I allready found something like this:
page.headerData.20 = PHP_SCRIPT_EXT
page.headerData.20.file = fileadmin/phpScript.inc
...but this inserts the file to template, I just want to show it on one single page instead of content. The application is currently included as an iFrame (same domain) but that's not the best way because the window doesn't resize.
In also think abouth to convert the whole app to typo3 plugin, but I'm very new to typo3 so I don't now how to start. Is there a guide for converting plain php to typo3 plugin?
Hi you can use a simple user extension.
Some where in Typoscript Setup:
includeLibs.mystuff = path_to_file/my_user_class.php
lib.mystuff = USER_INT
lib.mystuff {
userFunc =user_myclassname->main
var_to_pass_at_class=test
}
--
Now you can replace the subpart with dynamic content (depends on your TYPO3 configuration)
+- page.10.subparts.CONTENT<lib.mystuff
--
File: my_user_class.php
<?php
class user_myclassname {
function main($content,$conf){
global $TSFE;
return $conf['var_to_pass_at_class']; //returns test
}
}