|
-
May 26th, 2013, 05:25 AM
#1
Thread Starter
Hyperactive Member
Returning specific information with ->ID, ->Account, ->Mail, ->Skype etc...
(With one main function like User(), but without user class)
I don't really have idea what is smart way to create bunch of information picked up with the "arrow" I actually know what are they, but I don't know how to explain or what ever it is that I can search it from google.
But I want it to be like this:
function User($Name) {
// Other shiiieeeeet
}
Example results:
<?php $User($_SESSION['account'])->ID; ?>
<?php $User($_SESSION['account'])->Account; ?>
<?php $User($_SESSION['account'])->Mail; ?>
<?php $User($_SESSION['account'])->Skype; ?>
I can use such a feature for logged in users as I can use it for profiles like this.
<?php $User($_GET['profile'])->ID; ?>
<?php $User($_GET['profile'])->Account; ?>
etc...
But I don't have a clue how do I create "inner function" / "nested function" or whatever that I can use it with arrow. I've seen such a thing before, but it doesn't really help me just now. If I create functions inside of function I cannot use them with arrow.
Any ideas? Thanks!
-
May 26th, 2013, 01:16 PM
#2
Addicted Member
Re: Returning specific information with ->ID, ->Account, ->Mail, ->Skype etc...
thats mvc programming and theres a bit different between php (mvc) and php it self , if you wanna code the mvc way u use "->" , i recommend you search for php mvc programming it can help you
-
May 27th, 2013, 07:03 AM
#3
Re: Returning specific information with ->ID, ->Account, ->Mail, ->Skype etc...
How about creating a class that will accept the ID via its constructor and you could use this object later by calling it's properties/functions.
PHP Code:
class User {
public $ID; public $Account; public $Mail; public $Skype;
public function __construct($id) { fetchUser($id); } public function fetchUser($id) { $this->ID = $id;
//do some DB fetching and assign the values from the DB to the class's data members. I am assuming a variable $row is containing the datarow of the query you executed on DB. $this->Account = $row['Account']; $this->Mail = $row['Mail']; $this->Skype = $row['Skype']; } }
// ---- Usage
$obj = new User(123); //create the Class's object passing the ID to the constructor
echo $obj->ID; echo $obj->Account; echo $obj->Mail; echo $obj->Skype;
// ---- If you want to fetch another user ID's data:
$obj->fetchUser(3564);
echo $obj->ID; echo $obj->Account; echo $obj->Mail; echo $obj->Skype;
This is a simple demonstration only. You have to improve it and take care of the rest of the things!
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 1st, 2013, 03:19 AM
#4
Re: Returning specific information with ->ID, ->Account, ->Mail, ->Skype etc...
I'm not sure exactly what you're looking for.
Perhaps it's the 'magic' function __get, which lets emulate members without explicitly defining them:
PHP Code:
<?php class User { private $dict; private function __construct(array $props) { $this->dict = $props; } public function __get($key) { return $this->dict[$key]; } public static function lookup($name) { return new User(['name' => $name]); } }
$u = User::lookup('John Citizen')->name . "\n"; ?>
I'm not sure why you'd want to do that, to be honest.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|