Mixing CodeIgninter (PHP) with Backbonejs - php

I just want to ask, does it make sense to use both a PHP backend MVC structure, mixed with a front end js MVC structure?
My question arises from building a web application in CodeIgniter, I've begun working with websockets and nodejs so a lot of my interactions to the front end don't even touch php. Currently though the only way to change content in my database is to go through CI via ajax calls.
Is there any advice and how to create and maintain both MVC structures? or should this be avoided.

As you already said: CodeIgniter is a MVC framework. As you're using BackboneJS you won't need the VIEW-part of CI and the MODEL-part won't be needed that much.
You could use CodeIgniter as a simple API backend that handles as a middleman between your frontend and the database (there are very good xmlrpc libraries for CI out there!) or you could go for a REST-specific framework like Recess (http://www.recessframework.org/), try this: https://stackoverflow.com/questions/238125/best-framework-for-php-and-creation-of-restful-based-web-services
Short answer: your php-backend would just serve as a API-provider which is used by BackboneJS, so you could use any framework as long as it fits your needs - and CodeIgniter seems to do that.
Tip: you can just delete the libraries and helpers from CodeIgniter that you won't need for you API.

Related

Laravel 5.5 and angular 4 integration

I am working on a ERP system that is 6 years old and it is developed in raw PHP maintaining procedural coding structure without OOP or any Framework.
Finally our management decided to re-write the application with upgraded technologies. We will write the application in Laravel Framework. Database will be Oracle and Mysql both. In the front end we will use Angular 4.
The confusion is should i use Angular 4 for front end request handling and data binding? Or i should go with Javascript/Jquery. Last few days i am seeking some suggestions on the net. I found some also. My question is, how should i integrate Laravel and angular? should i go for API based approach maintaining two different project for Laravel and Angular or angular inside Laravel in a folder? If i go for API based approach, will my ajax request increased? The database of the application will be too large.
will API based approach make data loading slower?
All the request in the application will be ajax based and there will be no page refresh approach, but url will change on request.
Please suggest me the possible right solution to help me taking the right decision.
Angular 2/4+ has been designed to build SPA (Single Page Application). If you deep dive into angular then it will be clear to you that all the structures and conventions followed in the angular 2+ architecture are optimized for SPA.
So, if you want to use Angular with Laravel 5+ then I think the best way would be to use angular to build a standalone frontend application and use Laravel 5+ as a backend. That means laravel will act as an API server and a backend of the application.
Using laravel as an API server doesn't necessarily mean your database will be bigger. It is actually upto you how you design your application.
But, there is an another good solution.
You can use VueJs. There is a build in support for VueJs within Laravel 5+.
The benefit of using VueJs is that you can use it just like Jquery. That means you don't have to create separate standalone application for VueJs like Angular.
But, you can use it, page by page basis. It is loosely coupled.
You will get most of the benefit of Angular from it.
You can also use React.
You can use Angular 4 to rewrite your application. Fontend as Single Page Application and Backend exposing REST API will help you to build a good performance application.
I prefer to keep Angular and REST API separate as they should be independent to each other. REST APIs should always be generic so that they can be consumed by other applications too.
Yes, there will be lot of API calls to server. You can scale your REST APIs according to your number of requests. It is better building micro-services to ensure most of the services will not be impacted in case of lot of heavy load (at least part of application will be running). It will help you in future maintenance also.

Using Codeigniter in Zf2

I have an project that is used by many users and it's written in Codeigniter. I'm very happy with my application but I'm getting lost with Codeigniter because of the functionality of the framework and my application is getting too big for Codeigniter (that is what I think).
I want to go from Codeigniter to Zend, but the application is too big to begin all over again because there is still more functionality to come.
I don't know if someone has experienced or tried it, but does anybody know if it is possible to integrate Codeigniter into Zend as an module and migrate in steps to the Zend Framework 2?
Sorry for my bad english by the way :-)
Having experience with small and medium-scale projects with both CodeIgniter (CI) and Zend Framework (ZF), I can tell you that using one framework over the other will not solve any problem you might be having.
If you are looking for the added functionality provided by the ZF components, such as a ready-made class for Date or the Form verification class, know that you can use ZF components in Code Igniter. You will need to create a special class in CI that will jumpstart the ZF class autoloader. From there you can simply include ZF classes and use them as if you were inside a ZF application.
See http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/ and http://fr.slideshare.net/samsonasik/codeigniter-using-third-party-components-zend-framework-components for more details.
"Integrate" means you want to put your app running on CodeIgniter withing ZendFramework. So basically you changed nothing and there's no much sense of doing so.
You perhaps could consider porting your app from CI to ZF, but that will require rewriting of your code. But I'd first try to find out what the bottleneck in your app really is and ensure that you will benefit from the switch

is it advisable to use yii framework for jsonrpc only app??

Is it advisable to use yii framework (or any other php framework) for application handling jsonrpc requests only?
I am confused between
creating my own file/folder structure with oop,
AND
using existing yii framework (or any other php framework)
Can anyone suggest, what i should do?
Is there any other php framework available to do same.???
Thanks
A framework will cut down the amount of development, particularly for something like JSON request handling (which is build into Yii) and thus you would get the project off the ground more quickly and have less code to maintain.
However, for you, there is, of course, the Yii learning curve ... but I reckon it would be worth it in the long run...
How big is your project?

PHP framework that can be included in other projects

I have a little specific concern, I hope you can help me, I have to develop an application in PHP that doesn't need to be linked to the exclusive use of its installation and could be used or "included" in other projects of PHP, I mean, to develop a web application (such as generation of a graph according to certain parameters passed) that can be used on different pages created for example in phpBB, Drupal, Dreamweaver or PHP Frameworks like CodeIgniter and Zend.
The best example of what I mean is "Google Charts Tools", you just print in the browser the access to the tool with the parameters and the tool does the rest, and this does not depend on the type of framework with which the home page was created.
In short, I'm looking for a framework or lightweight framework with which I can develop an application that simply could be called in an include() or require() on the destination page and can be used, a framework that can somehow "export" the project or application and could be used on one page without having to reinstall the framework on the target server, even the libraries could be included in the target page so you can run the application.
Was working with Codeigniter and tried to attach to a Joomla page but i couldn't because Codeigniter is linked to the URL of the page and I dont want to use Iframes.
Is there something like that?
First of all; I believe you would need some custimization, as frameworks just aren't build that way. But it isn't impossible. In Kohana for example (also codeigniter, but kohana is more flexible), you can build internal requests with Request::factory($uri). If you can find out a way to bypass direct access to index.php, or build a wrapper after which you can do stuff in the Kohana 'environment' you could do it. I don't have a ready-to-use solution, but if you try something and post the code we might be able to help you out some more!
Sounds to me like you want to write a library or class that can do certain things and which can be reused in other code. You can then build an example application around it, using a framework, which uses this library.
If you start with a whole framework, this often makes it really hard to reuse any part of the code, since the framework has certain assumptions or requirements which may not always be true for other projects. As a general rule: a framework is already a complete standalone application. What you want is something smaller than that.
Of course, you can have a look at a framework like Zend, which is basically just a loose collection of individual classes. Together they form a framework, but each part of it is individually usable. Something like CI is on the other end of the spectrum, much more heavily coupled and interdependent.

Building a REST API quickly from a Database model

I've designed my database diagram(11 entites) for my prototype application. I need to have an REST API on top of this that will allow me to build a prototype android tablet application that talks to it.
Considering this is only for prototype purposes. What would be the quickest way to get a API up and running that would allow me to get, put, delete etc..
Security at this point isn't an issue so even if all add edit delete were open that would be fine.
My initial idea is to build this with PHP and MySQL maybe using the Yii framework to help but I feel there might be something that might be faster for my purpose.
Any thoughts or recommendations or advice?
It is worth looking into API rapid-prototyping tools like Apify (tutorial) since you're starting from scratch. If you're planning to have both an API and a Web site accessing the same data, consider using one framework for both as it helps prevent duplicating logic. CakePHP and Yii are good examples of multipurpose frameworks that are suited for this type of development.
If Python is an option, it is trivial to use a light-weight http framework to build a REST API that accesses a database.
Here's a snippet for a fully functioning http server using the itty framework: https://github.com/toastdriven/itty/blob/master/examples/web_service.py and https://github.com/toastdriven/itty/blob/master/examples/posting_data.py
Look at this project which allows you to create an API REST in seconds.
https://github.com/GeekyTheory/Automatic-API-REST
Features
Creation a powerful API REST of your MySQL Data Base in Seconds.
Management of the API in situ, it is not neccesary an extra data base.
Private tables and fields.
Custom queries.
Installation
Clone the repo.
git clone https://github.com/GeekyTheory/Automatic-API-REST/
Place it in your web folder /var/www/YourWebPage/
Open the file config.php and complete all the fields with the server credencials.
Go to domain.com/AutomaticaApiRest

Categories