How to filter requests in codeigniter - php

As I'm new to PHP previously i worked on JAVA, currently for my web application i'm using codeigniter. I want to configure a filter where i can filter every request to identify whether any harmful data is coming from user or not(same as java filter).

Codeigniter have Security and Input Class, Look:
http://ellislab.com/codeigniter/user-guide/libraries/security.html and
http://ellislab.com/codeigniter/user-guide/libraries/input.html
AFAIK, That's all you can get. CI is just a small (IMO) Framework. If you want more, you need to create your own by creating library and/or extending the core.

Related

AngularJS and PHP backend

Maybe it's not a real question, rather is's a discussion. I decided to learn angular, using a simple task, build a blog system. And i have a few questions.
Lest imagine that the php app will have the MVC structure, so i have some questions:
Should i build my back-end only as RESTFUL app, and use json response\request upon the angular and php?
What about the view in php app, i should use them with ng-init?
Routing, server side or client side?
What about caching?
And the last, but not the least, where i should put the logic about data that user will input?
Can someone give me the instructions or directions, about this things, and maybe useful link's to read the articles, to combine the php and angular, or maybe i'm doing it in the wrong way?
You might want to consider this type of application as actually TWO applications.
The first is the backend, the API. You can use your PHP framework to build an API that will allow you to have data persistency, validation (business logic), etc... and forget about the front end for now, you are only building an API for the backend data.
The second part of the app is the AngularJS frontend. This includes all of the views and everything that the client sees. None of that is coming from the backend.
This allows you to use the backend API (the PHP bit) to act as the data store, with it's own validation for safety, while having the seamless user experience and basic client side validation from AngularJS.
Routing is AngularJS, as that is the actual frontend that the client is using.
Caching can be done (if needed) in the backend, your API.
Validation will happen in both the frontend and the backend, although they can be slightly different if need be.
Remember, you build the backend strictly as an API, without consideration for the frontend (as if there will be more than one app using it), so it will have it's own validation rules and logic.
Hope that helps.
I have found a very simple structure that allows me to utilize Angular with PHP and restful api's. I use Angularjs for all views. I use a restful PHP API framework called slim to facilitate the communications between Angular and the PHP models which I use Doctorine2 for.
85% of my coding is done with Angular(Views). 5% done with the API(controller) and the remaining 10% configuring business logic in the Models. Great separation of concerns and not much overhead. Simple and concise.

Architecture for a Codeigniter Based application

I am looking at suitable architecture for a Codeigniter based application , the requirement is such that end of the program I must be able to reuse certain modules , completely.
I was looking at a solution like HMVC.
I need to know if this is the best solution for my problem.
To build a set of independent modules that can be reused with minimal changes.
Regards,
Gayan
At what level do you want to reuse "modules"? For example, the models that you create could be reused on a different web application, since they will simply be an interface between your web application and the back-end database.
If you create REST web methods using a framework such as CodeIgniter REST Server, those methods might also be at a suitable level of generality that they could be re-used as well.
I suppose the next question is, do you need and entire 'module' of code that can be copied out of this app and pasted into another one? If that is what you are looking for, then HMVC would be the final piece of the puzzle that you can use to tie everything together - just create this general code within one or more modules.
Does that help at all?

Can we do Custom PHP/Mysql with ExpressionEngine

I'm looking into expressionEngine as a CMS for a project i'm working on. I'm not sure if EE works with Custom PHP/JQuery. I'm want to allows users to upload images, Each user's images would go into the user's folder named after his userid. User can then access his uploaded images y clicking on show all images... Something along this liken. I have this done in Pure PHP, but the questions is can this be done in EE and how efficient or easy it is to do so.
I don't see why you couldn't accomplish these things within EE. EE has some good image gallery setups, and custom programming (as of EE 2.0) relies on CodeIgniter.
http://www.packtpub.com/article/expressionengine-creating-a-photo-gallery
Be willing to learn the "EE" (now "CodeIgniter") way of doing it. But sure, you could easily build your own system on top of EE.
http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-file-uploading-and-image-manipulation/
A bonus is that the EE community is very friendly and active. Plus there are some great developers, such as Leevi Graham:
http://leevigraham.com/
http://ee-garage.com/
And some more specific examples:
http://codeigniter.com/user_guide/libraries/file_uploading.html
http://jefim.eu/blog/2009/10/image-file-upload-with-codeigniter/
http://codeigniter.com/forums/viewthread/80610/
Some more good information:
http://net.tutsplus.com/articles/web-roundups/30-awesome-codeigniter-tutorials-for-all-skill-levels/
I haven't touched ExpressionEngine a lot, but I have done some freelance work for designers who have used EE. You can use templates in EE and inject your own PHP code into them no problem. You just have to tweak a couple of settings on a per template basis (enable PHP code and set PHP processing to occur at either the input stage or the output stage - not entirely sure what the effect of that is though).
Basically, yeah you can use your own PHP in EE.
ExpressionEngine (EE) is based on CodeIgniter (CI) a free PHP (MVC) framework. So you you may have to create a custom controller and model to do this but its a simple request so should be easy. Start here: http://codeigniter.com/
As mentioned above, there are several ways of achieving the functionality that you're seeking. The easiest methods involve relying on a couple of carefully crafted conditional statements in EE template code, but this method would dump all images into one folder (instead of storing them within a folder named after each user's ID).
If you find that you really want to break out of this structure and store each user's photos in a unique folder, you could use the EE API. The API allows you to do many powerful things and can be much more convenient to use than standard PHP , depending on the task at hand.

CakePHP integration with ExtJS 3

I am a PHP and ExtJS user. I am looking into developing an application using a good PHP framework (CakePHP; good as in "I consider this good for me") and ExtJS version 3. What I would like to achieve is a complete Ext viewport with many grids and functions that would call PHP urls for retrieving data, saving data, edit/remove data (not just for grids, also for treepanel and such). I would like to use CakePHP as backend with all its capabilities for executing these functions. My first goal is to integrate the obAuth component (or any other secure authentification plugin for CakePHP) with an ExtJS 3 login interface. I am searching for the best method of combining these too so that I can easily restrict functions based on the usergroup access. I am thinking of a setup where the logged in user makes one post from Ext regarding the execution of a function and the CakePHP response made present as errors or notifiers through Ext alert boxes.
Do you think this is possible ? Any thoughts of an ideal config for this ?
Thank you.
If you're going back and forth between JavaScript and Cake a lot the first thing you might want to do is override or extend the default View class so it'll package variables you set in the controller automatically into a JSON array or whatever you prefer. That'll save you from having to make a view for each action and/or overriding the layout each time. Study cake/libs/view/view.php and/or cake/libs/view/media.php, you can create custom views in app/views/.
Make use of the RequestHandler Component a lot to reuse logic both for normal views and AJAX.
Beyond that it's normal JS with a PHP backend.
This is actually very easy. First, integrate the obAuth Component into a basic CakePHP install, to see if it works properly and doesn't have any strange quirks. Once that's done, get to work on your frontend.
Your frontend should be designed entirely with ExtJS components. Either design your frontend with ExtJS or via HTML templates, but try not to do both, as it gets confusing and hard to maintain. I recently did this, and every controller action had a view that set up the DOM with some basic elements (a header for the page, any divs I needed to bind components to, and the .js file that was specific to that page/view).
Then, make your application RESTful. All of your ExtJS components can read data from a DataStore (or can just take a URL as the data source), so you just give them the paths you'd like and you're done.
Check out Bancha, it integrates ExtJS 4 and CakePHP 2.
It does this by doing all the communication in the background using an completely implemented Ext.Direct for CakePHP.
cheers
Roland

Shortcuts for creating/modifying web forms in PHP?

I'm new to PHP and before I waste a lot of time doing things the hard way, I wanted to find out if there are shortcuts/techniques to creating PHP web forms apps. All this app will do is display web forms with data from 1 or more tables. In addition to displaying data, the user must be able to update the form and add new data to the forms. I know how to to do all this by manually writing all the PHP/HTML code. But I'm looking for anything that can save me time.
Unfortunately, I can't use any of the fancy PHP libraries such as CakePHP for this. I'm restricted to using the core PHP framework, Oracle for the database and the OCI library for Oracle access.
Given these constraints, what the easiest way to support CRUD operations in a basic PHP forms app? Are there code generators or other tools that can help?
Unfortunately, I can't use any of the fancy PHP libraries such as CakePHP for this. I'm restricted to using the core PHP framework,
Most PHP frameworks are written in PHP. So you wouldn't have to install anything to use them.
That said, forms are rather non-trivial. Treating a form as a separate component only works to some extend. Because of that, many frameworks have forms deeply integrated into them, and not as a standalone component.
You could take a peek at Zend Framework's (now known as Laminas) Form component
. It's fairly self-sufficient and feature-rich.
I build all of my forms on top of a "fillInFormValues($html, $request, $formErrors);" function. See my article at OnLamp for details and full source code.

Categories