Coder Social home page Coder Social logo

nuzulfikrie / cakephp-react Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hassifmohd/cakephp-react

0.0 1.0 0.0 456 KB

Using CakePHP with React but not SPA (single page application)

License: MIT License

Shell 3.61% Batchfile 0.67% PHP 80.54% CSS 10.29% JavaScript 4.89%

cakephp-react's Introduction

CakePHP+React

About this project

  • This is sample CakePHP v3.7 application with React.
  • What interesting is the react is non-SPA (non single page application).
  • This means when you run npm run build the webpack will create multiple bundle.js located here
  • If you want to read which code I change when putting React into this CakePHP, please refer this PR

The concept behind it

If you have events/view in CakePHP controller and you want to change it into React. Below is the list of files that is related

Files / Folders Descriptions
app folder CakePHP application folder
frontend folder This is where I install the React application
app/src/Template/Events/view.ctp Put React related code
frontend/webpack.config.js Add new entry point and target location to transpile the code. IMPORTANT!
frontend/src/events-view/index.js Your React application code. Run npm run start for development
app/webroot/js/events-view.js This is example of the transpiled code used by view.ctp when you run npm run build

Installation CakePHP

Start

First is to install CakePHP

git clone [email protected]:hassifmohd/cakephp-react.git //download this sample
cd cakephp-react/app //go into the cakephp folder
composer install //download the cakephp

Setup CakePHP database

After install CakePHP you need to setup the database first

cd cakephp-react/app/config
cp .env.default .env //create a .env file from the template given
vim .env //update you configuration
vim app.php //update Datasources to use env(...) that you just set

Test CakePHP is running

If you setup everything correctly. You should be able to access the website now. Mine is http://localhost:8080/cakephp-react/app/

Create table using migrations and sample seed data

Create the table database using CakePHP migrations

cd cakephp-react/app/
bash bin/cake migrations migrate //create table
vendor/bin/phinx seed:run -s EventSeeder -c config/phinx.php -e development //create sample data

Test CakePHP is running

Once again, if the setup is correct. You can access http://localhost:8080/cakephp-react/app/events/add

React development

React development located at frontend folder

  • located at frontend folder
  • In this project. I make events/index and events/view as react
  • So you will see app/src/Template/Events/index.ctp is different
  • The bundle.js is different which is app/webroot/js/events-index.js
  • If you want to look at the code, please compare this and this
cd cakephp-react/frontend
npm install //install anything important. start the project

Development

To develop, run npm run start change anything at frontend/src/events-index/index.js

Development: Add new module

Let say you want to make events/add to use react. Change frontend/webpack.config.js according to the entry. I am using multiple entry point. Therefore when you develop the webpack will automatically create new file at /app/webroot/js/event-add.js

Build

To build simply run npm run build

cakephp-react's People

Contributors

hassifmohd avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.