PDA

View Full Version : extjs and php example



Shabneez
14 Jan 2013, 10:10 PM
Hello,

Could anyone please provide an example of a formpanel with fields and buttons, that uses MVC pattern to perform crud operations based on php backend? Im trying to do this:
41272

my store has the api config for crud operations to be performed and point to the following:

<?php
include("db_connect.php");

function create( $result )
{
$query = "insert into student (stud_id) values ( $result->stud_id)";
mysql_query( $query );

$result = array( 'success'=>true, 'data'=>true );
echo( json_encode($result ) );
}


function read()
{
$query = "SELECT * FROM 'student'";
$qResult = mysql_query($query);
$listResult = array();


while($row = mysql_fetch_array($qResult))
{
array_push($listResult, $row );
}

$result = array( 'success'=>true, 'data'=>$listResult );

echo( json_encode($result ) );
}


function update( $result )
{
if( isset( $result->id ) )
{
$query = "UPDATE student SET name = '$result->name', WHERE id = $result->id";
mysql_query($query);

$result = array( 'success'=>true, 'data'=>true );
echo( json_encode($result ) );
}
}

//D
function destroy( $result )
{
if( isset( $result->id ) )
{
$query = "DELETE FROM student WHERE id = $result->id LIMIT 1";
mysql_query($query);

$result = array( 'success'=>true, 'data'=>true );
echo( json_encode($result ) );
}
}

$action = $_GET['action'];

if( $action )
{
if( $action == "read" )
{
read();
}
else
{
$result = file_get_contents('php://input');

if( isset( $result ) )
{
$result = json_decode( $result );

if( $action == "update" )
update( $result );
else
if( $action == "destroy" )
destroy( $result );
else
if( $action == "create" )
create( $result );
}
}
}
mysql_close($con);
?>

Please could anyone provide an example how perform crud operations, I dont quite grasp the whole thing.:(( Im using sencha architect.

existdissolve
15 Jan 2013, 6:30 AM
Try this article: http://joekuan.wordpress.com/2011/01/10/how-to-use-ext-js-crud-php-example/

Shabneez
15 Jan 2013, 6:57 AM
:((
I haven't understood what the person from the blog saying :((