React.js and PHP together? - php

I'm looking to rewrite an old website using React.js for my frontend framework and PHP for the little backend stuff I may need.
The server I'm using is IIS with Apache, but I have little/no SSH access/ability to install stuff on the machine (i.e. npm, node, etc.), so I'm restricted to using PHP as a backend (so I can't build/compile my React JSX serverside). However, couldn't I simply just upload built/compiled my react files to the server?
I have seen this, but I'm not entirely sure that I need it?
Basically, my question is, is using these two together practical? Would I need any other tools to accomplish this? (The website is likely to be pretty small.)

I've used PHP and React together briefly (and then moved on to isomorphic React). Running V8 with PHP is only useful if you need server-side rendering (for fast initial loading and easy SEO), but I've not tried it so I'm not sure whether it's stable/reliable enough. If you do not care about server-side rendering, then you can just build the React app and include it in your PHP view.
Basically, the PHP view would serve as a layout, with a React container element defined so that your React app can bootstrap with it.
You can also pre-fetch the initial data for the React app with PHP and somehow attach it to your PHP view. The simplest way would be to use a script block to assign the JSON-serialized data to a global variable. Another way would be to define element(s) and attach your JSON-serialized data as element attributes, to avoid globals. Either way, you'd have your Flux stores bootstrap with those initial data to avoid having to hit APIs before the app can load.

Related

Vue.js (CLI) + PHP

I'm relatively new to practical web development, so I apologize if the question is stupid. The crux of the problem: I only want to use Vue on the front end of the site, and on the back I am using a PHP framework (or not a framework, it doesn't matter). Connecting Vue to every page via a CDN seems to be wrong to me. I didn't quite understand how the CLI works, does it generate some kind of static files (like a compiler), or does it definitely need Node? And did I understand correctly that I can't use things like Vuex and vue-router without node.js? Thank you in advance!
VueJS and vue-router are totally independent JavaScript framework and router, you do not need NodeJs to use them, you might get confused after using npm but npm is just a package manager, using it is a matter of choice.
The ClI or currently #vue/cli is just a command line that you can use to create new projects and control them, run them etc, using it isn't required when using vue trough a CDN.
About PHP:
There are a lot of ways to use VueJs in PHP but the most convenient one would be creating a PHP API in the back-end and a normal Vue and Axios app in the front-end, this approach is the one you should get used too because its easily implemented in other languages and even PHP frameworks, for example WordPress.

Laravel 4 with Ember App

I am creating a web application. I am fairly accustomed to Laravel and how it functions. I would like to know how I incorporate Ember into the Laravel setup. I am guessing public folder, but when I use Yeoman to install Ember into the public it involves the node_modules and gruntfile. My question is should all this be in the public folder (any security concerns?)
Some people say it is not good to mix the two. I would like multiple single page views so it makes sense. Plus it is a good challenge to get stuck into. I have researched any answers and had no luck.
You need to put your script files in your public folder, otherwise the clients browser wouldn't be able to fetch and use them. No security concerns there. That includes grunt, bower or any other files (if it happens that you need them in your production server).
We at work use Laravel and Ember. Ember is our true front end and Laravel is our true back end. It is a very good idea to use them together. It's also a good idea to start with multiple apps so you don't get overwhelmed in no time. In time, you can evolve to one huge app and/or you'll start writing components and mixins you can reuse across your apps.
Just a note: I use a combination of bootstrapped data (json_encoded in .blade views) and data fetched from the server via getJSON (I don't currently use Ember Data because is not production ready yet)
I hope this helps you!

Using App Engine Python application as proxy to PHP application

During the past two years I have built an App Engine application in Python. Soon it will be possible to use PHP on App Engine. I would like to use off-the-shelf PHP applications such as Wordpress, Mediawiki and phpBB together with my Python application. To the user it should be transparent which of the two applications (Python or PHP) she is using for a particular page. I consider the Python application to be the main application where I will do most of the programming. This is because I have more experience with Python and also because I already have written a lot of reusable code for App Engine.
Currently my approach is to build a proxy in Python that maps HTTP requests like this:
http://www.yellow.com/blog/* to http://phpapp.appspot.com/wordpress/client1/*
http://www.yellow.com/community/* to http://phpapp.appspot.com/phpbb/client1/*
yellow.com is a domain mapped to my Python application.
http://www.blue.com/wiki/* to http://phpapp.appspot.com/mediawiki/client2/*
http://www.blue.com/* to http://phpapp.appspot.com/wordpress/client2/*
blue.com is a domain mapped to my Python application.
Besides the blog, community or wiki, there are a lot of URL's that don't require PHP. These URL's are handled by the Python application. For example: http://www.yellow.com/admin/*.
I'm still struggling with the proxy to get the passing of cookies between the two applications right, but I think it's possible to do this.
It would be awesome if I could get it to work this way. However, it seems to me this is not the most elegant way to handle this. I know I could use subdomains to serve the PHP applications, but I would rather just use URL patterns. Also, with the proxy approach, I can tweak the returned HTML by the PHP application before serving it to the user. Another advantage of this approach is the ability to cache the pages from the PHP applications in memcache.
I would like to hear what you think of my approach to use Google App Engine (custom) Python and (off-the-shelf) PHP applications together. Will I run into problems with the proxy (Javascript, cookies, ...)? Would it be better to build everything in Wordpress, for example, with custom plugins written in PHP (the plugins could fetch data from the Python application)? Other suggestions?
Your use case is a good example of what Appengine's Modules are intended for. Take also a look at the dispatch mechanism.

How to combine Flash ActionScript with PHP?

I am new to using flash and I need to make a web application using CodeIgniter with PHP.
I have some doubts about the MVC pattern applied in codeigniter.
I'll use ActionScript because I see that is most used and less complex. (correct me if I'm wrong)
Are my views (which are in the folder view) would separate my files in Flash?
Any IDE assist me in programming flash with php?
Should I create a separate Flash application from another application to connect php?
Any consideration to be taken into account?
Thanks in advance.
I'm not sure if "combine" is the right word here. If you integrate PHP, ActionScript and CodeIgniter, you'll actually be writing PHP within the CodeIgniter framework and then embedding Flash .swf files into your views.
If you plan on using this combination, what you'll need to do is map out your site and determine which parts are going to be done in PHP and which parts need to be done in Flash (or ActionScript).
My recommendation: Only use Flash where unescapably necessary. That is, use CodeIgniter for your website pages and to integrate with your data sources (via PHP) and create REST endpoints (via CodeIgniter) for data that needs to be accessed via your Flash implementations. Then, create your Flash (or Flex) application that needs to handle the audio recording and embed that into one of your CodeIgniter views.
Re:
I'll use ActionScript because I see that is most used and less complex (than FLEX).
IMO, Flex (and MXML) is essentially just a markup language for ActionScript. It actually gets compiled into ActionScript when you build your .swf file. So, choosing ActionScript vs. Flex is just a personal preference. If you're more familiar with the Flash interface than the Flex Builder interface, then go ahead with ActionScript exclusively. However, for what you say that you want to build (an audio recorder), there are already numerous examples of those available in Flex.
As far as an IDE discussion, for PHP - whatever you're familiar with. If you're looking for a full-featured IDE, I'd recommend something like PHPStorm. You can also get by with any text editor.
For Flex or ActionScript, you'd almost have to go with Flex Builder or Flash.
Try looking at amfphp (http://www.silexlabs.org/amfphp/) if you want to connect flash and PHP.
We used it for the commercial release of flash/flex based games with a PHP/Apache backend.

Include Mediawiki in php application

Is there a way from my PHP application to include a single file from the MediaWiki installation, and everything would work fine?
I first tried doing an iFrame, but clicking some of the links inside the iFrame doesn't work.
It seems that only possible way to use MediaWiki engine for your own application is to install a separate instance on it on your server (source + db). Then you'll be able to use it through API.
Pros:
Easy to update;
Can be used with any application built on any platform;
Cons:
It's not too easy to install and maintain MediaWiki;
You should use external interface for it even from your script. Say, you should use CURL requests from your PHP application to your Wiki even if they are situated on one host.
Large overheat, 'cause you can't use only Wiki-parser.

Categories