Run PHP script?

  • Apologies in advance if this has been addressed elsewhere, but how do you get PHP to execute in PageKit? For example, putting the following in the Code section doesn't render Day/Time like in a normal PHP page, wondering where in PageKit it does.

    PHP
    1. <?php
    2. // Server is Central Standard Time
    3. $today = date("D g:i A");
    4. echo $today;
    5. echo ' (CST)';
    6. ?>

    Thanks!

  • As far is i know, i would say you need to create an extension for that.

    Correct.


    Depending on your requirements it could be even easier to do that by an extension. It's not difficult to create an extension and we can help you out with that :)

    If you'd like to use something like "inline-PHP": This is often not recommendable. I know that there are extensions for WordPress or Joomla!, which provide something like that - but in the past there have been security issues with this - because the PHP-code is often being executed using exec (my provider does not even allow that ;) ) and if there's a possibility to modify the original PHP, almost everything will be executed.

  • Thanks again for the replies. I started reading about extensions. So unlike typical PHP pages, you can't do calls to MySQL, run PHP code blocks or use SSI in the HTML itself, but have to use extensions for that?

  • Hi bobafifi


    Well - what do you mean with

    typical PHP pages

    ?


    I don't know what this should be...? Maybe you mean a output of pure PHP in your browser?


    If so: No. That's not possible for good reason - and it's not possible in most popular CMS without plugins or hacks I wrote about in my last reply.


    The question is: What do you want to archive? It is really easy to extend Pagekit - but to do that, you need to know what you want to do. Depending on your requirements you could:


    • Write your own extension (maybe even a big one with custom routes, an API, controllers, ...)
    • Write an extension (maybe it's enough to write a small one that consists of 3 files only (index.php, composer.json, scripts.php))
    • Write an extension that provides a content-plugin
    • Add the stuff you need to a theme


    So maybe it would be a good idea to tell us what you want to archive :) I'm sure there's a solution for that :)

  • Thanks. I'd like to understand how to use dynamic elements like Server Side Includes (SSI) within PageKit


    PHP
    1. <?php require '…/includes/example.php' ; ?>


    or run a MySQL calendar script (which I use on other non-CMS sites) or even how to execute a PHP generated "Hello World!" in the program. Thanks again for all your help with this!

  • Hi...


    Alright... Well - Pagekit makes massive use of namespaces. So try not to include files manually, when it comes to your first extension.


    A "hello world"-extension is really easy to do.



    Have a look at:


    1. https://spqr.wtf/blog/2017/08/…pagekit-part-1-the-editor
    2. https://spqr.wtf/blog/2017/08/…agekit-part-2-first-steps
    3. https://spqr.wtf/blog/2017/08/…3-model,-view,-controller
    4. https://spqr.wtf/blog/2017/08/…pagekit-part-4-namespaces
    5. https://spqr.wtf/blog/2017/08/…kit-part-5-the-first-view


    And:



    If you simply want to write a "hello world" extension, you can do this with a 2-files-extension (index.php and composer.json).



    Should be something like that:




    It's not tested - but should be something like that ;)

  • Thanks! I'll check out the links.

    Thanks. I'd like to understand how to use dynamic elements like Server Side Includes (SSI) within PageKit


    PHP
    1. <?php require '…/includes/example.php' ; ?>


    or run a MySQL calendar script (which I use on other non-CMS sites) or even how to execute a PHP generated "Hello World!" in the program. Thanks again for all your help with this!

    Good morning, bobafifi. Did you solve your PHP challenge and wrote a plugin? If so, would you be willing to share?