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.

  • 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?

  • I found pagekit today, I must say admin UI is best I've seen in a modern way. I come from Joomla environment.

    And I too need to run snippets of PHP/JAVA code in my pages. I see there is no such way here in pagekit :(


    In Joomla you can create a module then place it anywhere you like (in any page position), then you put your code in it and that's it. Here after reading all this thread I have no idea what are you talking about guys. My native language is not english maybe that is why.


    Anyway not being able to use PHP in pages and in widgets that are something like modules in joomla is stupid and very limiting at best. TYPO3 users will lough to death if they come across pagekit.


    I understand that running PHP is a security issue, but having admin write some sort of extension to run few lines of PHP is CRAZY !

  • Hey there,


    welcome to the sinking boat :) well you can use following extension to integrate java script or css snippets within a breeze.


    https://pagekit.com/marketplace/package/spqr/assets


    Beside that you can integrate what ever you want with php / vue js 1.x to extend pagekit to your personal needs. If you coming from joomla as me, then you will surely not missing much except masses of extensions or templates. Over all it's still lightweight in compare to joomla and way more secure. In last alsmost 5 years of using pagekit, not even one site was hacked so far.


    Good starting point is searching for specific topics here in our community forum and of course the pagekit documentation. At last but not least, the documentation for UIKIt v2 when you are using the original yootheme templates or v3 when used some community templates is very helpful too. It is a UI Framework giving you the possibility for creating your own layouts as lightning fast, modern UI visiual effects and functions.


    Regards,


    Fossy

  • I installed the assets and javascript works fine, but I need to use PHP and that does not work.


    I'm using tipso.js to make a tooltip on an image. Then I use PHP time expiration script to show current or expired image with it's tooltip. I then use the <?php @readfile("URL to the php file"); ?>

    This pulls the whole code and inserts it in the page where it must appear.


    I would happily use a javascript if it can replace the PHP altogether, but I don't know how to do this I'm not much of a programmer :(


    My current code, somebody helped with 3rd tier quotes I was looking for solution for 2 weeks !

    The

    Code
    1. $expireDate = strtotime("2017-12-31");

    This makes the scritp show one set of images or the other.

  • Sveiki,


    Well the extension I mentioned to you is exactly only for js and css.


    As I wrote you already before. For php you will have to write an extension or just extend your template for an extra widget position, which is pretty similar compared to Joomla modules positions.


    It is not much what you want to reach but other wise I don't know any other possibility. We are a community based forum if you didn't know that and are not related to yootheme.


    As you won't get any help from them anyway, you are welcome here to stay and learn how to make progress even without being a programmer with an cms like pagekit.


    I help everyone except kuzmich as good as I can, but I'm not an programmer too and still in very beginning of code writing.


    Regards


    Fossy


    P.s. a key ready solution you won't get in most cases, when you want it for free. Otherwise you can hire for sure someone who can help you to achieve what you want.

  • It's easy to show PHP-content with JavaScript :)



    Step 1:

    Install "Assets" module.


    Go to Admin -> "Assets"


    Make one asset.


    Make it a JavaScript-asset:

    Set Status to "Published".

    Type "Inline".

    Click "Load dependencies": "jQuery",


    Insert example code inside "Code":


    $(document).ready(function(){

    $("#div1").load("test.php");

    });



    Step 2:

    Upload a file test.php to server.


    Insert example code inside the PHP-file:


    <?

    echo "Today is " . date("Y/m/d") . "<br>";

    ?>



    Step 3:

    Go to Admin -> "Site".


    Insert HTML-code:

    <div id="div1"></div>



    You are done!

  • That sound really easy, will it work with enabled .htaccess too?