{"id":1599,"date":"2018-01-19T19:23:02","date_gmt":"2018-01-19T19:23:02","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/adobe-flash-builder-4-data-centric-features-for-php-page-2\/"},"modified":"2018-01-19T19:24:55","modified_gmt":"2018-01-19T19:24:55","slug":"adobe-flash-builder-4-data-centric-features-for-php-page-2","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/adobe-flash-builder-4-data-centric-features-for-php-page-2\/","title":{"rendered":"Adobe Flash Builder 4: Data-centric Features for PHP Page 2"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By PHP Builder Staff<\/div>\n<div class=\"\">on June 8, 2009<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<div class=\"articleHeader\">\n<h2>Coding the Service<\/h2>\n<\/div>\n<div class=\"articlePara\"> Make sure that the PHP service<br \/>\nthat was generated is currently selected in the main window.<br \/>\nIf you are working in the full version of Flash Builder<br \/>\nwithout having installed a PHP editing plug-in, Flash<br \/>\nBuilder opens the generated service with a different<br \/>\napplication on your computer (most likely Adobe Dreamweaver,<br \/>\nif it is installed on your local machine; otherwise, it<br \/>\ndefaults to the application that is associated with the PHP<br \/>\nfile format). <\/div>\n<div class=\"articlePara\"> The PHP class that was generated<br \/>\nfor you is a stub for basic Create, Replace, Update, and<br \/>\nDelete (CRUD) operations that are typically part of a remote<br \/>\nservice. Uncomment the code within the operations of the<br \/>\nclass. You can use this code as a template for your<br \/>\nservices, or remove the code entirely and create the code<br \/>\nfor the operations from scratch. However, if this is your<br \/>\nfirst time testing the new data-centric features of Flash<br \/>\nBuilder, I strongly recommend sticking with the stub code<br \/>\nfor now. The service class used for this article was only<br \/>\nslightly modified: Basically, I replaced<br \/>\n<strong>item<\/strong> with <strong>user<\/strong> wherever it<br \/>\nappeared. You will also need to change the database<br \/>\nparameters accordingly as well as table names and fields<br \/>\nwhere they appear so that they correspond with your actual<br \/>\ndatabase. The application built in this article pulls<br \/>\ncontact information from a table called<br \/>\n<strong>User<\/strong>, so I had to modify the service stub<br \/>\naccordingly. <\/div>\n<div class=\"articlePara\"> When you are finished coding the<br \/>\nservice, you must configure the return types for each<br \/>\noperation. However, before you do that, this is a good time<br \/>\nto open the package that was added to the Package Explorer<br \/>\nfor your project earlier. The package is named<br \/>\n<strong>services<em>.UserService<\/em><\/strong><em>,<\/em><br \/>\nwhere <strong><em>UserService<\/em><\/strong> is the name that<br \/>\nyou assigned to your service.<strong> <\/strong>In this<br \/>\npackage, you will find two classes. The one that holds the<br \/>\nsame name as your PHP service that is intended for<br \/>\ncustomization. Notice that the class extends your service&#8217;s<br \/>\nsuper class. The name of the super class will have<br \/>\n<strong>_Super_ <\/strong>attached to the beginning of the<br \/>\nservice name. Do not modify this class. You can override any<br \/>\nof the methods in the super class as necessary. <\/div>\n<div class=\"articleHeader\">\nConfiguring Return Types\n<\/div>\n<div class=\"articlePara\"> Your Flash application must know<br \/>\nwhat to expect for the data type that will be sent and<br \/>\nreturned for each method. To configure your method return<br \/>\ntypes, right-click one of the operations from the<br \/>\n<strong>Data\/Services<\/strong> tab, then click<br \/>\n<strong>Configure Return Type<\/strong>.<strong\/>\n<\/div>\n<div class=\"articlePara\"> This process can be a bit tricky<br \/>\nif you aren&#8217;t aware of a few things. First, it is best to<br \/>\nconfigure the <code>getAllUsers<\/code> method first.<br \/>\nAssuming that your service does not have any errors, you<br \/>\nshould get a response with an object that has more objects<br \/>\nin the payload, provided that you inserted a few entries<br \/>\ninto your database for testing purposes. Next, enter a name,<br \/>\nsuch as <strong>User<\/strong>, as shown in Figure 6. <\/div>\n<p>\n<a href=\"Images\/figure6.png\" target=\"newFrame\"><br \/>\n<br \/><img decoding=\"async\" src=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/figure6tn.jpg\" border=\"0\"\/><br \/><font size=\"3\"><em>Click here for larger image<\/em><\/font><\/a><br \/>\nFigure 6\n<\/p>\n<\/p>\n<div class=\"articlePara\"> This is the new process for<br \/>\ncreating value objects. You can still code value objects the<br \/>\nway you did with Flex Builder, but it would be<br \/>\ncounterintuitive to use the same methodology with Flash<br \/>\nBuilder, considering the speedier workflow you gain by<br \/>\nletting Flash Builder automate this process for you. Plus,<br \/>\nthe value objects that Flash Builder generates are more like<br \/>\nvalue objects on steroids, in that they do a whole lot more<br \/>\nthan just wrap a bunch of values for strong data typing<br \/>\nbetween the client and server. For example, the return type<br \/>\nset for <code>getAllItems<\/code> is a <code>User<\/code><br \/>\nobject, even though it is actually a collection of<br \/>\n<code>User<\/code> objects. This is because the auto-<br \/>\ngenerated result handlers are smart enough to know the<br \/>\ndifference between a single <code>User<\/code> object that is<br \/>\nreturned versus a collection of <code>User<\/code> objects.<br \/>\nIn other words, you don&#8217;t have to type the result to an<br \/>\n<code>ArrayCollection<\/code> and go through the whole<br \/>\ntyping, binding, and object-mapping process as you would<br \/>\nhave done with Flex Builder. <\/div>\n<div class=\"articlePara\"> When configuring the<br \/>\n<code>getAllUsers<\/code> and <code>getUsers_paged<\/code><br \/>\nmethods, you&#8217;ll have to shift the paradigm that you may have<br \/>\ngotten used to with previous versions of Flex. In the past,<br \/>\nyou would have declared an <code>ArrayCollection<\/code>,<br \/>\ntyped the response data to it, and then bound your list or<br \/>\ndata grid to the variable. There were also things like class<br \/>\nmapping, which made the process even more difficult.<br \/>\nLuckily, that&#8217;s all in the past. <\/div>\n<div class=\"articlePara\"> So, the code that was generated<br \/>\nwhen your value object was created is smart enough to figure<br \/>\nout when it has a collection of User objects as opposed to a<br \/>\nsingle User object. Therefore, as you can see in Figure 7,<br \/>\nthe return types for <code>getAllUsers<\/code>,<br \/>\n<code>getUser<\/code>, and <code>getUsers_paged<\/code> are<br \/>\nall of type <code>User<\/code>. <\/div>\n<p>\n<a href=\"Images\/figure7.png\" target=\"newFrame\"><br \/>\n<br \/><img decoding=\"async\" src=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/figure7tn.jpg\" border=\"0\"\/><br \/><font size=\"3\"><em>Click here for larger image<\/em><\/font><\/a><br \/>\nFigure 7<br \/>\n<\/p>\n<div class=\"articlePara\"> When you configure the<br \/>\n<code>updateUser<\/code> operation, you could send the ID and<br \/>\nuser details as a single object or two separate objects&#8217; it<br \/>\nreally doesn&#8217;t matter. The main thing to understand is that<br \/>\nyou are not sending a <code>User<\/code> object here. The PHP<br \/>\nservice does not care about the strongly typed<br \/>\n<code>User<\/code> object you have on the client side, nor<br \/>\ndoes it need to. Just send the data as an Object, as seen in<br \/>\nFigure 8. <\/div>\n<p><a href=\"Images\/figure8.png\" target=\"newFrame\"><br \/>\n<br \/><img decoding=\"async\" src=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/figure8tn.jpg\" border=\"0\"\/><br \/><font size=\"3\"><em>Click here for larger image<\/em><\/font><\/a><br \/>\nFigure 8\n<\/p>\n<\/p>\n<div class=\"articlePara\"> The reasoning for sending the new<br \/>\nuser data over as a generic Object is clear upon reviewing<br \/>\nthe Structured Query Language (SQL) statement that was auto-<br \/>\ngenerated for the PHP service stub: <\/div>\n<p><code><br \/>\npublic function updateUser($userId, $user) {<br \/>\n\u00a0\u00a0$this-&gt;connect();<br \/>\n\u00a0\u00a0$sql = \"UPDATE User SET last_name = '$user-&gt;last_name', first_name = '$user-&gt;first_name',<br \/> <br \/>\n\u00a0\u00a0email = '$user-&gt;email', phone = '$user-&gt;phone', company = '$user-&gt;company', job_title = <br \/>\n\u00a0\u00a0'$user-&gt;job_title', person_type = '$user-&gt;person_type', lead_source = '$user-&gt;lead_source',<br \/>\n\u00a0\u00a0tags = '$user-&gt;tags' WHERE  id = $userId-&gt;id\";<br \/>\n\u00a0\u00a0mysqli_query($this-&gt;connection, $sql) <br \/>\n\u00a0\u00a0or die('Query failed: ' . mysqli_error($this-&gt;connection));<br \/>\n\u00a0\u00a0\u00a0\u00a0mysqli_close($this-&gt;connection);<br \/>\n}<br \/>\n<\/code><\/p>\n<p\/><\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"wallace20000608.html\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"wallace20000608.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">2<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"wallace200006089ba9.html?page=3\">3<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"wallace20000608fdb0.html?page=4\">4<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"wallace200006089ba9.html?page=3\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to take advantage of the new data-centric features of Flash Builder to increase your workflow<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1599","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1599"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1599\/revisions"}],"predecessor-version":[{"id":2317,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1599\/revisions\/2317"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}