View Full Version : ExtJS API for PHP

12 Jan 2012, 4:53 AM

i want to write an PHP Application with ExtJS.
The PHP should generate some ExtJS JSON and here is my problem.
All Examples create the JSON as strings and not from a standard way e.g. some classes.

So my idea was to have the ExtJS API as PHP classes. Than i could create an object and set some properties and than call toJSON().
With this way i have in every place i use a panel the same class (api) and not only a string or an array.

Knows someone, if and where i could find something like this, or if i had to do that by myself.

12 Jan 2012, 11:07 AM
So you want Ext.data.Store as a PHP class?

12 Jan 2012, 11:41 AM
Thanks for your answer.

I want e.g. Ext.panel as a PHP class or better the needed structure to create a panel.

Now i have to write somthing like this:

$panel = "Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
html: '<p>World!</p>',
renderTo: Ext.getBody()

-> or an associative array...

This will be returned from my php zend action to the browser which runs the code.

I want to write in the action something like this:

$panel = new PhpExtPanel();
$panel->title = 'hello';
return $panel.toJSON();

So i have a standard class which i could use in every action in need it.
And i haven't in all actions stings or arrays.

I hope this explanation is better to understand

12 Jan 2012, 4:36 PM
This does what you're after -

Although, I wouldn't recommend it's usage. You'll never have the latest and greatest ExtJS features, and this seems like it would limit the flexibility of ExtJS.

My recommendation - read up on MVC architecture and use Ext.Direct.

Oh and - that project hasn't been updated since 2008, so I wouldn't expect much from it...

13 Jan 2012, 1:15 AM
Thanks Erikvip, I agree with you:
2008 that's not good :-)

Ext.direct is good to get data from DB or something. But could i do the following with it:
The Plan:
- it's a complete ExtJS builded website

1. User logs in.
2. He sees the "desktop" with a menu. This menu is loaded from DB (works)
3. Now he want to start an applikation/modul he clicks on "user administration"
4. Then opens a window with a grid.

- here is the problem, every user could have other privileges
- e.g. he may not see the column: age or he has other limitations
- so the idea was to create the views, panels and whatever by php dynamically

Because this, i want to build @ php window with a grid and submit this to the browser.
Now the grid has the limitations and it knows where to finde the needed grid data.

This window could be used in "thousands" of modules and I will not have the configuration json string/array in any module , as this error could occur.

15 Jan 2012, 3:15 AM
Normally for doing that, I create separate permissions as bit fields in the database, then check them when the view is being rendered & hide/show components in JS. Of course, you'll still need to verify permissions on the PHP controller, but that will give you dynamic views.

So i.e., I make a table with permissions like, perm_view_users, perm_edit_users, perm_admin, etc. When the user logs in, I store this in a session & setup a user.permissions object.

Then, when building the view, you can do things like:

Ext.create('Ext.Panel', {
hidden : ( !user.permissions.perm_edit_users == '1' )


if ( user.permissions.perm_edit_users == '1') {
Ext.create( ...

So the view is only visible to users with certain permissions. Then of course on the back end:

public function update_user($args) {
if ( !$this->has_permission('perm_edit_users') )
throw new Exception('access denied');

Notice that you'll need to perform this check in both places for security (client and server side).

I would recommend using pure ExtJS instead of a PHP wrapper though. You'll find better help online & can use all the latest features.