PHP - How To Instantiate A Model
Can a person instantiate a model? If so how do you do it. I already know how to instantiate a class
thank you Similar TutorialsHi, I'm newbie to php opp. I just need to know if it is possible to instantiate a class like this? $import = new geoIpImportCSV(obtainDownloadFileName(), 'table1'); class geoIpImportCSV { private $input_zip_file; private $db_table; function __construct($input_zip_file, $db_table) { $this->input_zip_file = $input_zip_file; $this->db_table = $db_table; } /* "GeoLiteCity_" . $date . ".zip". */ function obtainDownloadFileName() { return "GeoLiteCity_20101201.zip"; } // ... } It is possible to call a method(obtainDownloadFileName()) like this to the constructor? Best Regards, class Database { // actual database interaction // also uses mysql_real_escape etc. } class Users extends Database { function checkIfUsernameExists() { } } class addUser extends Users { // perform all add user stuff } class searchUser extends Users { // all search user stuff } So, to add a new user, I would instantiate, then perform various queries to the addUser class, probably also using the checkIfUsernameExists method in the Users class. Finally, Database would add the record. Question: what do I instantiate? Do I instantiate just the addUser one, or first the Database class? I know how to do it, but what about instantiation, using parent:: self:: etc. etc. (how do I link these clasess together is what I think I mean). Is this an acceptable way to instantiate classes?
//$_SESSION['product'] = {'ProductA', 'ProductB', ... 'ProductX'} $p = new $_SESSION['product'](); $p->save();I am usually used to calling out classes explicitly where class name is not a variable but a hardcoded string. Sometimes I use if/then/else in order to do this. Here it is a variable and it bothers me a little bit. But PHP allows me to do this. Is this an acceptable latest & gratest modern PHP object oriented web technology technique or not ? I am developing a new promising service (media-industry) in the Los Angeles area. Contact me if interested.
Leroy. liroyleshed@gmail.com Hi, I have a cakePHP program that works and displays data from a database table. The part I dont understand and I couldnt find anything on the cakephp blog as yet was the model was left blank? q1) The model is left blank but still works so what is the default behaviour here for the model? It doesnt seem to be needed to do anything i?. q2)I am selecting all the data from 1 table but how do I add a sql statement to select part of the table or a join of 2 tables? the find 'all' seems to just do that only in finding all data from a table. <?php class Post extends AppModel { /*var $name='User';*/ } ?> <?php class PostsController extends AppController { public $helpers=array('Html','Form'); public function index() { $this->set('posts',$this->Post->find('all')); } public function home() { $this->set('posts',$this->Post->find('all')); } } ?> view /// .. <?php foreach ($posts as $item): echo '<tr><td>'. $item['Post']['id']. '</td>'; echo '<td>'. $item['Post']['title'].'</td>'; echo '<td>'. $item['Post']['body'].'</td>'; echo '<td>'. $item['Post']['created'] .'</td>'; echo '</tr>'; endforeach; unset($item); ?> Hey all,
I am making a application that requires a user to login in. I have a user model, which does such things as finds, registers, logins in, updates etc a user. It also grabs all of a users data from a database, such as their username, email address etc and checks whether or not a user is logged in.
The problem I face is this. I want to control what content a user can see depending on if they are logged in or not. In addition to this, I want to output the users data, such as their username, in other parts of the website – such as the header and footer. There is no real easy way of doing this, and requires the user model to be instantiated on every page. My question is should this class be a model or just a core library class?
Hello I'm developing a Model-View-Controller framework for my personal learning curve. I've created an active record class and I've got stuck when using variables in a where clause. My problem is this: When, in a where statement, you want to find the Users with the first name Mike, you might write SELECT Firstname, Surname FROM Users WHERE Firstname = 'Mike' Where Mike is enclosed with quotation marks. When you're comparing entities quotation marks shouldn't be used. For example, SELECT Firstname, Surname, OrderTitle FROM Users, Orders WHERE Firstname = 'Mike' AND Users.Firstname = Orders.Firstname So when using variables in my where statements, like $Name = Mike $this->Where(Firstname',$Name); $this->Where('Users.Firstname','Orders.Firstname'); How do I differentiate, in my function Where() when to enclose the string with quotation marks, i.e when it is a (Table.Entity) rather than a constant. Thank you Hi Everyone. I am in need of assistance, I need a form that i will use on a model agency site i am making, the form i have only has the option to upload one image and records name, age etc... What i need is a form that will upload multiple images, 2 will do but if i had a option to add more that would be great, and a pdf resume, does anyone have a similar form i can have a look at that does this, any help be awesome, i am already over the deadline. This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355229.0 Hi all,
I was just wondering is this possible what I'm trying to do?
Models can only store one object at a time...
I'm trying to access multiple objects via one model...
<?php class users extends Model { protected $username; protected $firstname; protected $secondname; protected $age; // There will be more here... public function __construct($id = NULL) { if($id != NULL) { $this->username = $sql->getUsername($id); $this->firstname = $sql->getFirstname($id); $this->secondname = $sql->getSecondname($id); $this->age = $sql->getAge($id); } } public function numOfUsers() { $num = $sql->countAllUsers($query); return $num; } public function getUsername() { return $this->username; } public function getFirstname() { return $this->firstname; } public function getSecondname() { return $this->secondname; } public function getAge() { return $this->age; } }; class UsersView extends View { $users = new users(); for($i = 0; $i < $users->numOfUsers(); $i++) { $user = new users($i); echo "Username: {$user->getUsername()}"; echo "Username: {$user->getFirstname()}"; echo "Username: {$user->getSecondname()}"; echo "Username: {$user->getAge()}"; } }; ?> This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=318251.0 Dear Members, I am a PHP developer and desisgning a WAP page for mobiles.I need some php code to find out the model of a mobile phone from where request is coming so that based on that information I can upload the proper CSS for my page.If you can give me some hints as well that would also help me to proceed further.Currently I am able to fetch user-agent of mobile but not able to find out the specific model of mobile. |