Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Using SmartClient with PHP

    Can I use SmartClient with PHP and MySQL?

    Thanks

    #2
    PHP AND MySQL

    Hi Friends,
    I am also a web developer in PHP and want to use SmartClient AJAX GUI System.
    How i will integrate in my own website? Please Help...........................

    Comment


      #3
      Yes, several customers are already doing so. Start here.

      Comment


        #4
        I have just started going live and am having excellent results with PHP.

        I am using PDO_ODBC with custom PHP scripts to return JSON results to
        SmartClient. The PHP scripts look at the post from smartclient to do
        its work. PHP arrays are sent back to smartclient using the "JSON_ENCODE"
        verb in PHP.

        The PDO classes of PHP are very similar and I think there like 8 servers
        supported in addition to ODBC.

        Comment


          #5
          PHP + Firebird

          I have had success fetching records from Firebird and PHP. What I do not have clear is: how to make php read smartclient responses. for example, when you create a restDataSource and want to perform an Add operation, I do not have clear what is my PHP script going to receive.

          I have this:

          isc.RestDataSource.create({
          ID:"clienteDS",
          fields:[
          {name:"id", title:"Código", primaryKey:true, canEdit:"false"},
          {name:"nombres", title:"Nombres", type:"text", length:20},
          {name:"apellidos", title:"Apellidos", type:"text",length:20}
          ],

          fetchDataURL:"cliente_fetch_rest.php",
          addDataURL :"cliente_add_rest.php",
          });

          I'm telling the datasource to use "cliente_add_rest.php" when it adds some data, but how does php receive that data? is it a POST and I can get variables via $HTTP_POST_VARS? help will be highly appreciated.

          Also, When I fetch data, Some characters do not display correctly. I get funny characters instead á or ñ. any idea of this? I'm displaying characters on a listGrid

          thanks in advance.

          Comment


            #6
            For inbound message formats, see the very end of the RestDataSource docs, near "Server inbound data formats"

            On the character issue, you may have set the character encoding wrongly - see the Internationalization topic for details.

            Comment


              #7
              Fetching data from php with portuguese character

              $nome ="Dr.ª Ângela José Conceição";
              $nome = utf8_encode($nome);

              ListGrid works fine

              Comment


                #8
                Programmer

                Hi,

                I'm a newbie to SmartClient (just a day!), so sorry if this is trivial.

                I can populate a TreeGrid with JSON data from a PHP script. (Much thanks to the person who mentioned json_encode()...that saves a lot of code).

                My PHP pumps out customers from a MySQL table. (The parent nodes). This is working fine.

                When the user clicks a customer, I want the customers' projects to appear in child nodes, which come from another, separate PHP script.

                1. Can it be done with separate PHP scripts, or do I need to create a hierarchical array in one PHP script? Where do I put the second URL? In a separate DataSource? How do I send the requested customer id to my second PHP script for getting the matching projects?

                2. I've read that each node needs a unique id. Since my customers and projects are stored in separate tables, how can I generate a unique tree-wide id? (I'm using an auto-increment id field in each table, but the numbers may overlap.)

                How do people normally do this?

                Thanks,
                Mike

                Comment


                  #9
                  Hi msatkevich,

                  1. If you want the PHP scripts to remain separate, we'd recommend switching the dsRequest.actionURL from an override of dataSource.transformRequest()

                  2. SmartClient needs a unique id in load on demand node because when a request is sent to the server to ask for child nodes, SmartClient needs to pass some value which identifies the parent node. You can generate unique ids - for example a simple scheme of tableName.numericPK - either on the server or as part of a DataSource.transformResponse() override.

                  Comment


                    #10
                    Hi,

                    1. From your answer, it sounds like having two scripts is not a normal practice. Don't I need to keep them separate? If it was one script, all the parents and children would be returned in one big chunk, which would take too long. Or am I missing something?

                    Also, my DataSource is using dataURL to get the top level nodes. So I only see this one place to put a URL...can you direct me to more info about actionURL and transformRequest() ? Or some sample code?


                    2. So are you saying to use string values like "customers.3" and "projects:27" or something like that? And this can be done in transformResponse() ? Is there some sample code for this?

                    Thanks,
                    Mike

                    Comment


                      #11
                      1. One script can return two different results based on parameters. There are advantages to keeping things in one script, such as centralized authentication, logging, and other cross-cutting logic. But it's up to you.

                      As far as more info, you may not have found the docs. Note it's searchable - anything you see mentioned here is a good thing to search for.

                      2. Yes, "customers:3" or whatever scheme appeals to you. In transformResponse(), dsResponse.data is a simple JavaScript Array of JavaScript Objects - should be easy to fill in these IDs. If you aren't as proficient with JavaScript, perhaps do it in PHP instead before json_encode() is called.

                      Comment


                        #12
                        Originally posted by bmcosta
                        $nome ="Dr.ª Ângela José Conceição";
                        $nome = utf8_encode($nome);

                        ListGrid works fine
                        Hy,

                        a very important detail that must be strongly pointed out (athough Isomorphic and bmcosta said it before):
                        It's not enough to use utf8_encode() you have to set the header also.

                        something like this:

                        Code:
                        <?
                        header('Content-Type: text/html; charset=UTF-8');
                        ?>
                        <response>
                        <status>0</status>
                        <startRow><?=$_GET['_startRow']?></startRow>
                        <endRow><?=$_GET['_endRow']?></endRow>
                        <totalRows><?=$nrec?></totalRows>
                        <data>
                        <?
                        while($row=mysql_fetch_array($query))
                         {
                           print '<record>'."\r\n";
                           foreach($fieldArray as $element){
                           print '  <'.$element.'>'.utf8_encode($row[$element]).'</'.$element.'>'."\r\n";
                          }
                           print '</record>'."\r\n";
                         }
                        ?>
                        </data>
                        </response>

                        Hope this will be helpful.

                        Comment


                          #13
                          Now I've got a problem:

                          I'm using restEditSave example with the code from http://www.smartclient.com/index.jsp#restEditSave

                          It's working fine util I modify a record by adding "&" character.

                          something like this:
                          Code:
                          <record>
                              <continent>North America</continent>
                              <countryName>United States &</countryName>
                              <countryCode>US</countryCode>
                              <area>9631420</area>
                              <population>298444215</population>
                              <gdp>12360000</gdp>
                              <independence>1776-07-04</independence>
                              <government>federal republic</government>
                              <government_desc>2</government_desc>
                              <capital>Washington, DC</capital>
                              <member_g8>true</member_g8>
                              <article>http://en.wikipedia.org/wiki/United_states</article>
                          </record>
                          In Firebug GET Params are fine, GET Headers OK and Response too.

                          The error from Firebug is this:
                          _3 has no properties
                          http://localhost/meserie/isomorphic/system/modules/ISC_DataBinding.js
                          Line 658


                          Thanks in advance,
                          John

                          Comment


                            #14
                            Hi JohnBlack,

                            XML does not allow a naked ampersand (&), it must be &amp;. This is reported as an XML parsing problem in the Developer Console, which you should always have open.

                            Comment


                              #15
                              Hey,

                              Thanks a lot for clearing that out.

                              It took some time to figure which was the mistake ( the naked &) and when I switched now to Developer Console I found out that tells you very clearly where is the problem... so thanks again :))


                              However, should I worry for other special char that XML dosen't allow?


                              Thanks,
                              John

                              Comment

                              Working...
                              X