Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Aug 19, 2015

CakePHP 2.* how to use custom complex sql Query with model

Let's suppose that we have MySQL database with table categories:

CREATE TABLE `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category` varchar(64) DEFAULT NULL,
  `description` varchar(64) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;


Then, in CakePHP framework, you want to call a simple query as you did it with mysql_query in PHP with no framework.

For that you have the class Model::query()

First, you build the model. You don't want to use predefined Models for a table (like the model Categories for DB table Categories). Because you want to use perhaps this query for extracting data from two tables which are related.

So,  first you have to create the model. For this you have to create the file APP/Model/Categs.php



class Categ extends AppModel {

    public $useTable = false; // it is mandatory to have this line. Whithout this line, 
                              //                                    the Controller will search for table Categ; it doesn't matter that you have a sql query  

    public function getDataFromMyTable(){
        $d = $this->query("SELECT * FROM  categories");
        return $d;
    }

}


Second, you have to create the Controller. The file will be: APP/Controller/CategsController.php


class CostsController extends AppController {
    
    
    public function index(){
        $this->loadModel('Categ');
    
        $rezQuery = $this->Categ->getDataFromMyTable();
        $this->set('cs', $rezQuery);
    }
}
?>


And now we have to create the view. We create folder APP/View/Categs (if this folder doesn't exists). And then we create the file index.ctp into this folder. The name of the ctp file should be the  same as name of the function from Controller. In index.ctp we write:


Nov 23, 2011

Learn How to Install Joomla on Your Website in Less Than 5 Minutes


You can learn how to install Joomla on your website in a number of ways. However, the simplest and by far, the quickest is through Fantastico. This usually takes about 1-2 minutes once you know how. In this article, we are going to cover just that.

So, here is the step by step process for installing Joomla on your own website.

1. Log in to your hosting account's Control Panel. This should usually be http://www.mydomainname.com/controlpanel, where 'mydomainnane' is replaced your own website that is hosted on that hosting account.

2. Look for the smiley icon that says "Fantastico" and click on it. This is where you will be installing the Joomla package from. Note that Sometimes, it may say "Fantastico De Luxe." Don't worry it is the same thing. Much like saying "my room" and "my bedroom" ;)

3. Look for "Joomla" under the "Content Management" category of scripts in Fantastico and click on it. Also, note that the title 'Joomla' may sometimes have some numerical suffixes showing which version it is. For example, the title may read "Joomla 1.5" for version 1.5 of the CMS. Just click on the most recent version and go to the next step.

4. Look for the hyperlinked blue "New Installation" link and make sure you have at least as much as the minimum disk space required for you to install Joomla on your website. This is usually about 25 MB of disk space.

This is not usually
a problem, with most people's disk space running into the tens of gigabytes. But it is still good to make sure you have enough to hold a new Joomla installation.

5. Choose where on your website you want to install Joomla. Will it be on your main domain, an existing sub-domain or a new not-yet-existing sub-domain or directory? Indicate it in this part of the installation process.

6. Fill out other required fields that are required to smoothly install Joomla on the site. This includes creating an Admin username and password. Don't choose 'Admin' and 'password' as your username and password. Many people do this and have been hacked. Also, fill out the site name or main keyword, email address and other details here.

Then click the "Install Joomla" button.

7. On the next page, make sure that all the needed information is correct. Also, note down your Admin username, password and backend page (the one that ends with /administrator).

Finally, hit that "Finish Installation" of a button.

Voila! You have just learned how to install Joomla on your website. This should usually take only 1 or 2 minutes at most. After all, all you are doing is just hitting buttons, except for when choosing a username, etc.

If it still sounds a little like "nerd talk" (with all due respect to all the nerds out there ;) ), you can watch the video version of this article where you see the Joomla installation done live on the screen and see if you can learn how to install Joomla after that.

Aug 11, 2010

Tutorial WEBservice in PHP

In the last 2 weeks I have searched the simpliest and complete tutorial about webservices in PHP. I have founded followings:


One of the Internet's current hot topics is Web Services, introduced by Kevin Yank in his article Web Services Demystified.
If you've been following industry news on the subject, you may think this is some high level technology, of interest only to big companies with huge budgets. But if you did, you'd be wrong.
The concepts behind Web Services are remarkably simple, and in this article we'll be taking a deeper look at what's involved. Then, with a little help from our good friend PHP, we'll set up our first Web Service.
We will assume some knowledge of PHP, MySQL and XML, which -- if you're uncertain of -- you can quickly pick up from Building your own Database Driven Website using PHP & MySQLand XML - An Introduction.
So here's what's on the menu:
The Basics of Web Services: To start with we'll be quickly reviewing the basic concepts behind Web Services.
Introducing XML-RPC: Next, we'll introduce you to an XML standard for the exchange of data between systems, and we'll put it into context with Kevin's article.
PHP XML-RPC Implementations: Then we'll review some of the Open Source implementations of XML-RPC in PHP: code you can use to quickly build your own Web Service, or access other Web Services from your site.
Your first Web Service: If you want to get straight down to business, this is the place to be. Here, we'll take one of the implementations described previously, and build a Web Service for it in PHP.
What you can do with XML-RPC: Wondering what to do next? We'll give you some ideas for what you could do with XML-RPC and Web Services.
Let's get started!
The Basics of Web Services
The first thing to understand about Web Services is they're not really anything new. If you've ever used an RSS Feed to take news from another Website and place it on your own, you've already got a good idea of how Web Services work (see Kevin Yank's article: PHP and XML: Parsing RSS 1.0).
Web Services are about exchanging data between a server and a client, using a standard XML format to "package" requests and data so that both systems can "understand" each other. The server and the client could both be Web servers, or any other electronic device you care to think of.
Network-wise, data exchange in a Web Service typically happens via TCP port 80, using standard HTTP protocol POSTs. Put another way, Web Services operate in basically the same way your browser does when it POSTs an HTML form to a site, and receives a Web page in response. The only real difference is that, instead of HTML, Web Services use XML. And this means Web Services can be available anywhere on the Internet, passing through firewalls the same way viewing a Web page does. The data exchange happens at the packaging layer.
On top of the data exchange, you also need information that describes the interface (or Application Program Interface - API) to the service. This makes the Web Service useful to the rest of the Internet, allowing other developers to develop programs that can access your Web Service. This is called the description layer, and the WSDL (Web Service Description Language) standard that will make this happen is under development.
Above that, there's information that describes the nature of the service itself (not unlike the HTML-descriptive META tags), so that it can be categorised and found on sites that offer Web Service directories. This is the discovery layer, which is currently being addressed by the UDDI (Universal Description, Discovery and Integration) standard.
Both the description and discovery layers are simply XML, governed by a particular format that enables relevant information to be found for all Web Services on the Internet.
Perhaps what's made Web Services a hot topic recently -- aside from marketing by the likes of Microsoft and IBM -- is the development of these standards. They'll allow Web Services to be rolled out en masse across the Internet, backed by development tools that'll make access to them both predictable and easy.
But it should be remembered that everything a Web Service does now, in terms of data exchange, could also have been done 5 or even 10 years ago using the HTTP standard and whichever XML format you chose to use or invent (RSS feeds being a prime example). The "hot news" today is that building and distributing a Web Service is now a lot easier than in the past.
Anyway, if you're looking for a hype-free news source for the technological development in Web Services, try XML Hack.
We'll skip further generalities, but suffice it to say that this article focuses on the packaging layer, i.e. how you build and access a Web Service.

Aug 2, 2010

PHP start


Here we will write our first PHP code. And, after that some phrases about PHP variables.


Before you can work with PHP you need to install PHP on your computer if you haven’t installed PHP yet, now is a good time to install PHP.

First we will make a simple HTML page




Welcome to our first PHP tutorial.
 


Okay the above HTML page doesn't do anything special but just outputs Welcome to PHP tutorial on the browser, now lets add some PHP tags to it.

Note: All PHP code is written between  and ?> tags, now lets write "Welcome to our first PHP tutorial" using PHP.







   echo "Welcome to PHP tutorial";

?>



Okay the above PHP script will output Welcome to PHP tutorial note that we use the echo construct of PHP, the echo function simply outputs the content to the browser.

So if we wanted to write "Welcome" we would write echo "Welcome";

Note Have you noticed the ; at the end of the statment, Each PHP instruction must end with a semicolon.


Introduction to Variables
Let me introduce you to PHP variables, variables help you store and retrive data.

  • All variables start with a dollar sign $


  • The name of the variable can consist of letters and numbers, but must begin with a letter. It can also contain special characters like underscore '_', see some examples below

    $site = 'phpbuddy.com' // valid variable
    $4site = 'not yet'; // invalid variable starts with a number
    $_4site = 'not yet'; // valid variable starts with an underscore 

    Some more examples

    $testvariable = 1 + 1; // Assigns a value of 2.
    $testvariable = 1 – 1; // Assigns a value of 0.
    $testvariable = 2 * 2; // Assigns a value of 4.
    $testvariable = 2 / 2; // Assigns a value of 1. 

    Okay to make things easier I will show you an example here we will create a variables $a, $b and multiply them and store the value in $c, just see it's so simple
    
    
    
    $a = 5;  //we created a variable a and assigned it a value of 5
    
    $b = 2;  //we created a variable b and assigned it a value of 2
    
    
    
    $c = $a * $b;  //we multiply varaible a and b and store the value in c
    
    echo $c;  //we print the content of variable c which is 10
    
    ?>
    


    PHP variables can hold strings, dynamic data, PHP variables are case sensitive $a is not the same as $A

    
    
    
    $a = "Welcome to PHP ";  //$a holds the string Welcome to PHP
    
    $A = 4;  //$A holds the value 4
    
    
    
    echo "Variable a conatains: $a";
    
    echo "Variable A contains: $A";
    
    
    
    echo "$a $A";  //outputs both variables $a and $A
    
    ?>
    

  • Jul 9, 2010

    Analog Clock with JavaFX

    Last mounth just I have commenced learning JavaFX.

    I have entered on the site www.javafx.com and I have started with some tutorials. And after couple of hours I started with Analog Clock. And I have modified the code and I have saved as desktop application. And now rules like that:


    My code look like this:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */


    /**
    * @author Stefan Vilceloiu
    */

    //public class Main {

    import java.util.Calendar;
    import java.util.Date;
    import javafx.animation.KeyFrame;
    import javafx.animation.Timeline;
    import javafx.scene.Group;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.RadialGradient;
    import javafx.scene.paint.Stop;
    import javafx.scene.Scene;
    import javafx.scene.shape.ArcTo;
    import javafx.scene.shape.Circle;
    import javafx.scene.shape.Line;
    import javafx.scene.shape.LineTo;
    import javafx.scene.shape.MoveTo;
    import javafx.scene.shape.Path;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.text.Font;
    import javafx.scene.text.Text;
    import javafx.scene.transform.Rotate;
    import javafx.scene.transform.Transform;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;

    // varies according to scene size

    var width:Number = bind scene.width;
    var height:Number = bind scene.height;

    // list of months
    var months:String[] = ["IAN", "FEB", "MAR", "APR", "MAI", "IUN",
    "IUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
    var radius:Number = bind width/3; // Decides the main size of the clock
    var centerX:Number = bind scene.width/2; // Shifting the X center
    var centerY:Number = bind scene.height/2; // Shifting the Y center
    var hours:Number;
    var minutes:Number;
    var seconds:Number;
    var date:String;
    var month:String;
    var year:String;
    var combination: String;

    var time = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
    KeyFrame {
    time: 1s
    action: function() {
    actionOnTick();
    }
    }
    ]
    }

    time.play();

    //instance of calendar
    function createCalendar() {
    var date = new Date();
    def calendar = Calendar.getInstance();
    calendar.setTime(new Date()); // fix for mobile
    calendar
    }
    // action taken on one tick
    function actionOnTick () {
    var calendar = createCalendar();
    seconds = calendar.get(Calendar.SECOND);
    minutes = calendar.get(Calendar.MINUTE);
    hours = calendar.get(Calendar.HOUR);
    date = String.valueOf(calendar.get(Calendar.DATE));
    if(date.length() != 2) {
    date = "0{date}";
    }
    month = months[(calendar.get(Calendar.MONTH))];
    year = String.valueOf((calendar.get(Calendar.YEAR)));
    combination = "{date}-{month}-{year}";
    }
    //scene which can be dynamic
    var scene:Scene = Scene {
    width: 233
    height: 260
    fill: Color.TRANSPARENT
    content: [
    Group {
    translateX: bind centerX
    translateY: bind centerY
    content: bind [
    Circle {
    radius: radius + 20
    fill: RadialGradient {
    centerX: 0
    centerY: 0
    radius: radius + 20
    proportional: false
    stops: [

    Stop {
    offset: 0.9
    color: Color.SILVER
    },
    Stop {
    offset: 1.0
    color: Color.BLACK
    }
    ]
    }

    },
    Circle {
    radius: radius + 10
    stroke: Color.BLACK
    fill: RadialGradient {
    centerX: 0
    centerY: 0
    radius: 90
    proportional: false
    stops: [
    Stop {
    offset: 0.0
    color: Color.WHITE
    },
    Stop {
    offset: 1.0
    color: Color.ANTIQUEWHITE
    }
    ]
    }

    },
    Rectangle {
    x: -35,
    y: 2 * radius / 3 - 15
    width: 71
    height: 20
    fill: Color.GRAY
    opacity:0.4
    strokeWidth: 2
    stroke: Color.BLACK
    arcHeight:10
    arcWidth:10
    },
    Text {
    font: Font {
    size: 11
    name: "Arial"
    }
    x: -31 ,
    y: 2 * radius / 3
    content: bind combination
    },
    Text {
    font: Font {
    size: 11
    name: "Tahoma"
    }
    x: -24 ,
    y: -1.21 * radius / 3
    opacity:0.85
    fill: Color.RED
    content: "Vilceloiu"
    },
    for (i in [3, 6, 9, 12]) // Setting the main digits 3,6,9,12
    Text {
    transforms:bind [
    Transform.translate(-5, 5)
    ]
    x: radius * (( i + 0 ) mod 2 * ( 2 - i / 3))
    y: radius * (( i + 1 ) mod 2 * ( 3 - i / 3))
    content: "{i}"
    font: Font {
    size: 12
    name: "Tahoma"
    }
    },
    // making dots on rest of the place
    for (i in [1..12])
    if (i mod 3 != 0 ) then Circle {
    transforms:Rotate {
    angle: 30 * i
    }
    centerX: radius
    radius: 4
    fill: Color.BLACK
    } else [ ],

    // circle at the core center
    Circle {
    radius: 5
    fill: Color.BLACK
    },
    // one more circle inside the above circle
    Circle {
    radius: 3
    fill: Color.GRAY
    },
    // second arm
    Line {
    transforms: Rotate {
    angle: bind seconds * 6
    }
    endY: -radius - 3
    strokeWidth: 2
    stroke: Color.RED

    },
    // hour arm
    Path {
    transforms: Rotate {
    angle: bind (hours + minutes / 60) * 30 - 90
    }
    fill: Color.BLACK
    opacity: 0.8
    elements: [
    MoveTo { x: 4, y: 4 },
    ArcTo {
    x: 4
    y: -4
    radiusX: 1
    radiusY: 1
    },
    LineTo { x: radius - 23 y: 0 },
    ]
    },
    // minute arm
    Path {
    transforms: Rotate {
    angle: bind minutes * 6 - 90
    }
    fill: Color.BLACK
    elements: [
    MoveTo { x: 4, y: 4 },
    ArcTo {
    x: 4
    y: -4
    radiusX: 1
    radiusY: 1
    },
    LineTo{ x: radius y: 0 },
    ]
    }
    ]
    }
    ]
    };

    Stage {
    style: StageStyle.TRANSPARENT
    title: bind combination
    scene: bind scene
    width: 240
    height: 320
    }
    //}



    And now you can see my name on the clock and the current date in the bar (bottom)

    Jul 6, 2010

    MySQL tutorial - Managing database

    Creating Database

    To create a database in MySQL, you use the CREATE DATABASE statement as follows:
    CREATE DATABASE [IF NOT EXISTS] database_name;
    CREATE DATABASE statement will create the database with the given name you specified. IF NOT EXISTS is an option part of the statement, this part prevents you from error if there is a database with the given name exists on the database server. In our tutorial, for example, to create classicmodels database, you just only apply CREATE DATABASE statement above as follows:
    CREATE DATABASE classicmodels;
    After executing the statement, the MySQL will returns you a message to indicate whether the execution are successful or not.

    Showing Databases

    SHOW DATABASE statement will show all databases in your database server. You can use SHOW DATABASE statement  to check the database you've created or to see all the databases' name on the database server before you create a new database.
    SHOW DATABASES;
    On my database server, the output is :
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | classicmodels      |
    | mysql              |
    +--------------------+
    8 rows in set (0.00 sec)
    

    Selecting Database

    To select a database which you plan to work with, you use USE statement
    USE database_name;
    You can select our sample database by using the USE statement as follows:
    USE classicmodels;
    From now you can query the tables' data and do whatever you want inside the selected database.

    Removing Database

    Removing database means you delete the database. All the data and related objects inside the database are permanently deleted and cannot be undone. So it is very important to execute this query with cares. To remove the database you can use DROP DATABASE statement as follows :
    DROP DATABASE [IF EXISTS] database_name;
    Like CREATE DATABASE statement, IF EXIST part is an optional part to prevents you from removing database which is not existed. In order to practice with DROP DATABASEstatement, you can create a temporary database, show the database on the database server, and drop it step by step as follows :
    CREATE DATABASE IF NOT EXISTS temp_database;
    SHOW DATABASES;
    DROP DATABASE IF EXISTS temp_database;