How to call an Oracle Function in Symfony 2

Hi All,

How are you doing? Seems like my fingers do not want me to stay away from Symfony2 despite the Spring Bank Holiday. ūüôā

Today, I am going to talk about how to call an Oracle Function in Symfony2. A function (aka stored function) is a collection of SQL statements which is used to perform various different activities within the Database. The good thing about the function is you can write your chunks of SQL inside the function and call it using a name to initiate. I will be focusing on how to call an Oracle Function in Symfony2 and if you would like to know more about Oracle functions please click here.

First, let’s take a look at a sample function which I have created and is saved in Oracle 12c Database.

create or replace 
FUNCTION testFunc123(old_bname IN VARCHAR2) 
   RETURN VARCHAR2 IS 
   BEGIN 
      IF old_bname = 'TEST' THEN
          RETURN 'Y';
      ELSE
        RETURN 'N';
      END IF;  
    END;

The role of the above created Oracle function is to check whether the value of ‘old_name’ is equal to ‘TEST’ or not. If it is ‘TEST’, then the function will return ‘Y’ otherwise ‘N’. So, now what we going to do is call this function inside a Symfony2 controller. This is really easy, thankfully to wonderful Doctrine2.

Continue reading

Share

Create your first route | Symfony 2 | Beginners guide

Hey Symfony 2 lovers,

Let’s have a good understanding about routings in Symfony 2. Routing is the navigational paths (directives) in your application. For instance if you want to show all your products in your shopping cart application, which was developed by Symfony 2, routing could be either ‘your_cart/web/app_dev.php/show_all_items’ or ‘your_cart/web/app.php/show_all_items’. In here ‘your_cart‘ is the name of your application, ‘web‘ is the default path in Symfony 2 (you can hide this later), ‘app_dev.php‘ and ‘app.php‘ are two environments in the same application, such as development and production environment. These environments are there to distinguish your application in different purposes which I am not going to discuss any further. Our main concern in here is the ‘show_all_items‘ bit. This is a routing which fires a function in a controller. If you are new to a frameworks this concept might be little surprising to you. This is how the major frameworks work. When you hit a path, such as ‘show_users‘ will call a predefined function in a predefined controller. If you see something like this ‘show_users/10‘, probably that is to show how the user which has the id of 10, something like that. This 10, will be passed to a method as a parameter, such as ‘public function showUser($id)’.
Continue reading

Share

Create your first bundle | Symfony 2 | Beginners Guide

Hi All,

Welcome back. Today I am going to focus your attention on bundles. Well, the bundle is the most famous term you will frequently hear, during your adventure in Symfony 2. Actually, the bundle is a really handy feature which has been introduced by any PHP framework (not quite sure about rest of the frameworks) so far. Well, a Bundle is a package, collection of views, entities, controllers and so on. You can organize your code around bundles in a very smart way. And if you use bundles smartly, you can develop a system with highly independent features. Why not we discuss some examples before creating bundles,

  • Example 1 : Assume you are creating a basic employee management system. The basic features in a employee¬†management system are employee registration, employee profile, employee payroll, employee attendance¬†and so on. For employee registration, we have a separate UI with relevant registration form fields, we have separate functions (let’s call them controllers), such as checking existence of the employee, validity of the user input values, validity of employee national insurance number (in UK), and so on. And also, we got separate tables to insert values once the user submitted his/her employee registration form. Likewise we can group things (mainly model, view and controllers) in a functional way (but, it’s totally up to you).¬†We call¬†¬†these grouped things as ‘bundles‘ in Symfony 2.
  • Example 2: Let’s say you are creating a shopping cart system. In a shopping cart system, we know there are products, categories, sub categories, payment methods and so on. In here, we can have a separate bundles¬†for products, categories and so on. For an example, inside categories bundle, we can nicely arrange things which are mostly relevant to managing categories. These things can be views (html and associated js, css files and so on), models (tables, schema and so on) and controllers (functions such as adding a category, deleting category and so on). So, in here, we are arranging bundles in a logical way. Likewise, you can organize your bundles for products, sub categories and so on. Continue reading
Share

How to setup Symfony 2 in XAMPP | Beginners guide

Hi all,

Today, I will be showing you how to setup Symfony 2 in XAMPP environment. This is a real beginners guide, so this post is for beginners, and will be useful to fellas who are new to PHP frameworks, setting up frameworks in XAMPP.

  1. First thing you need to do is download the latest version of Symfony 2 from the Symfony 2 website. (The most latest version for this moment is 2.7) And also you need to download the most recent version of XAMPP from their website. (The most recent version is 2.4.17). Then install the XAMPP using default settings.
  2. I hope you have a working version of XAMPP and downloaded Symfony 2 zip file. Create a folder called ‘Symfony‘ inside this path ‘C:\xampp\htdocs‘.¬†¬†(If you haven’t installed under C:\ or installed in different directory, make sure you use that path).¬†Now what you have to do is, extract Symfony 2 zip file in ‘C:\xampp\htdocs\symfony‘ location. Continue reading
Share