Help building a interface

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
freakwillie
Forum Newbie
Posts: 6
Joined: Fri Jul 11, 2008 1:52 pm

Help building a interface

Post by freakwillie »

Hello everyone,

So, I'm very new to PHP and my former experience was with Java.

What I would like to know is if it's possible to make a interface with methods that ask information, threat the information sent and return something.

For clarifying a little I'm trying to do something like this:

Code: Select all

class Interfaces {
 
    public function getCar() {
        $result = "<form name=\"cadCar\">
        <h1>Car inclusion<h1>
 
        <p><b>Model: </b>
        <input type=\"text\" name=\"vM\" size=40 maxlength=80>
        </p>
 
        <p><b>Color: </b>
        <input type=\"text\" name=\"vC\" size=30 maxlength=40>
        </p>
 
        <p><b>Year: </b>
        <input type=\"text\" name=\"vA\" size=30 maxlength=20>
        </p>
 
        <p><b>ID: </b>
        <input type=\"text\" name=\"vID\" size=30 maxlength=20>
        </p>
 
        <right><input type=\"submit\" value=\"Inclui\"></right>  ";
        echo $result;
        return new Car($vM, $vC, $vA, $vID);
    }
 }
And have something like a "Main" class that creates a object of the class interfaces and call the method getCar() putting the result inside of a variable of the class Car. Something like this:

Code: Select all

require("Car.php");
 require("List.php");
 require("Interfaces.php");
 
 $l1 = new List();
 $i1 = new Interfaces();
 
 $c1 = $i1->getCar();
 
 $l1->addCar($c1);
Does that makes sense?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Help building a interface

Post by Oren »

Besides the name you gave the class ("Interfaces"), it has nothing to do with a PHP interface.
Anyway, why don't you just try and see if it works or not?
I didn't go through your code, only a rough look at the part where you created the instances for the classes and it seemed pretty usual to me. If you know Java I don't see why you need help in this. Anyhow, as I said, it was a very very rough look... just run this code and see what you get. If you get any errors you can always come back here and we'll help you in whatever you need.
freakwillie
Forum Newbie
Posts: 6
Joined: Fri Jul 11, 2008 1:52 pm

Re: Help building a interface

Post by freakwillie »

I don't really know what a PHP interface looks like, but I think it would be awesome if I could implement it using O.O. concepts just like in java, and havin to access just one page for a whole system.

Do you think thats possible? The specific problem I'm facing is how to handle the variables from the forms inside of the function.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Help building a interface

Post by Oren »

PHP interfaces look pretty much like interfaces in Java. See: http://docs.php.net/manual/en/language. ... rfaces.php
As for your problem, please be more specific and post the *relevant* piece of code (and use

Code: Select all

tags of course).
freakwillie
Forum Newbie
Posts: 6
Joined: Fri Jul 11, 2008 1:52 pm

Re: Help building a interface

Post by freakwillie »

Ohh, I didn't realize I could be interpretated this way. That's not the kind of interface I was refering to. I was talking about the user interface, you know, "the aggregate of means by which people—the users—interact with the system—a particular machine, device, computer program or other complex tools" (Wikipedia.org).
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Help building a interface

Post by Oren »

You still did not ask a specific question.
freakwillie
Forum Newbie
Posts: 6
Joined: Fri Jul 11, 2008 1:52 pm

Re: Help building a interface

Post by freakwillie »

What I would like to know is if it's possible to make a interface(sic) with methods that ask information, threat the information sent and return something.
I want to know how to make a USER interface class with methods that get the information from the user and use it to return something meaningful, all in the same method.

The example is in the first post.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Help building a interface

Post by Oren »

What you ask is like "how do I write a PHP script?". That's not a specific question. You'll have to be more specific and do your homework, cause the people over here won't do them for you.
zainal_se
Forum Newbie
Posts: 2
Joined: Tue Jul 15, 2008 12:14 pm

Re: Help building a interface

Post by zainal_se »

You are probably referring to a JSF-like Framework for PHP right? In which UI components can be reused over and over.

In PHP, I would advise you to follow the MVC Architectural Pattern. Model, Controller and View classes are separated and modularized.

Your View Classes may contain HTML codes in their methods, while your Controller processes which View should be deployed/displayed at any one time (through an event or user interaction). Your model does the data and business logic.

Or perhaps you can also use "SMART Templating" to improve your UI components and to easily manipulate them, edit them using a standard webpage designer.

Just keep on learning... PHP is very much friendly to Java Programmers. I am a Java Programmer by blood, but PHP is also close to my heart. 8)
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Help building a interface

Post by omniuni »

The easiest way to get basic input from a user is the simple query in the address. The interface in PHP is the web page itself that is generated by your code.

Code: Select all

<form action="?">
What is your name? <input name="name" size="30">
<input type="submit">
</form>
 
<br>
 
<?php
 
if(isset($_GET['name'])){
echo "Your name is: ".$_GET['name'];
}else{
echo "Please enter your name in the form above.";
}
 
?>
Post Reply