
ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
what would the concept/structure to create a booking system
ignace replied to Lisa23's topic in PHP Coding Help
nvm -
what would the concept/structure to create a booking system
ignace replied to Lisa23's topic in PHP Coding Help
If you are wondering how you would model this at a DB-level: driver (driver_id, ..) bus (bus_id, num_passenger_seats, ..) tour (tour_id, ..) schedule (tour_id, bus_id, driver_id, date, price) customer (customer_id, ..) booking (customer_id, schedule_id, ..) This should get you started. -
I can view the website now too but very slow, it took like 5 minutes just to load the frontpage and it was than still missing most images.
-
Sure you can, many others do it. Some even go as far as telling us to do THEIR work. Welcome aboard!
-
No, that should display whichever anything else is wrong due to the lazy initalization as you are actually doing this: $resources->getString()->replace('whatever', 'whichever')->replace('whichever', 'whichever')->show(); // should display "whatever" again You see This is also not true since str_replace accepts an array. Very few people seem to know this feature exists. str_replace(array("what", "name", "blah"), array("is meant","randomer", "hello"), $string1); echo resources::getString("alpha") // alpha ->replace("lpha","bravo") // abravo ->replace("vo", resources::getString("charlie")->show()) // should be abracharlie ->show(); // charlie This doesn't work because when you replace "vo" you set the static value of $string to "charlie" effectively trying to replace "vo" in "charlie".
-
problem with depositing and withdrawing cash in a banking system
ignace replied to heshan's topic in PHP Coding Help
account_number = account_id? Clearly customer and account are one and the same yet they share account_type and account_balance? And for some reason transaction has the same information? If one customer can have multiple accounts and that depends on your Business Requirements then the DB design should be something like: customer (customer_id, ..) account (account_id, customer_id, ..) If the customer and the account are the same thing then drop one of both and merge the columns with the other (or create an account_detail table). account (account_id, account_type_id, balance) account_detail (account_id, nic, full_name, initial, phone_number, address, gender, dob) This doesn't pass Normal Form 2 since not all data is atomic: full_name, phone_number, and address. I left interest_rate and fd_period out because I don't know what fd_period means and interest_rate seems to me something about the account_type_id but I'm not sure about this since I don't know anything about your actual Business Requirements. Transaction table then looks like: transaction (transaction_id, transaction_type_id, from_account_id, to_account_id, amount, log_date) -
Now you realize where your thinking went wrong it's time to ponder further and question your current design. Since you could make this mistake someone else using your API will too. How to solve? This of course depends on how you want your design to behave. You could implement Lazy Initialization, since you suggested a Singleton I think this is the way you want to go without actually implemeting the Singleton of course. class Foo { private $_string; public function getString(){ if (is_null($this->_string)) { $this->_string = xmlfile(); } return $this; } } This has a drawback that once the value is loaded from the XML it's not "refreshed" on subsequent calls. $resources->getString()->show(); // bla $resources->getString()->replace('bla', 'foo')->show(); // foo $resources->getString()->show(); // foo In contrast to your current design where it loads bla from the XML on each call to getString()
-
class Foo { private $_original = ''; private $_dirty = ''; public function getString() { $this->_original = 'whatever'; $this->_dirty = $this->_original; return $this; } public function show() { return $this->_dirty; } public function replace($thisstr, $thatstr) { $this->_dirty = str_replace($thisstr, $thatstr, $this->_original); return $this; } } #Use-Case 1 $resource->getString()->show(); // whatever $resource->getString()->replace('whatever', 'whichever')->show(); // whichever $resource->getString()->replace('whatever', 'what-eva')->show(); //what-eva Derived from: Which is different from: class Foo { private $_string = ''; public function getString() { $this->_string = 'whatever'; return $this; } public function replace($thisstr, $thatstr) { $this->_string = str_replace($thisstr, $thatstr, $this->_string); return $this; } public function show() { return $this->_string; } } #Use-Case 2 $resources->getString()->show(); // whatever $resources->getString()->replace('whatever', 'whichever')->replace('whichever', 'what-eva')->show(); // what-eva
-
http://pear.php.net/manual/en/installation.getting.php If you use XAMPP or WAMP or some other of these be sure to delete go-pear.phar and get the latest from http://pear.php.net/go-pear.phar
-
Your DB is lacking a proper design that's why it's so hard to retrieve the information. tv_show (tv_show_id, ..) tv_show_character (tv_show_character_id, tv_show_id, played_by, ..) actor (actor_id, ..) To get the TV characters and the actor information. SELECT .. FROM tv_show_characters T1 LEFT JOIN actor T2 ON T2.id = T1.played_by WHERE T1.tv_show_id = ?
-
Check your error logs
-
Creating a game is much more than just bashing out code. Among other things you'll also need to learn how to model and apply animation. You may be better off starting with Unity3D which has both free and commercial packages and provides you with an IDE to develop your game in. It has a decent rendering engine that supports most of the complex features you find in a game and it has a community from which you can "borrow" models, maps, .. Unity 3D Game Development By Example may be worth a look. A nice extra about Unity 3D is that it runs from within a web-browser (after installing the Unity client) so you can show your class-mates how cool you are from any PC
-
no that isn't normal as a result I can't visit your website as it can't translate the hostname to an IP-address.
-
Alternatively you can use extract which does somewhat the same thing like variable variables. Can you post the code that follows your while statement? Having more relevant code we maybe can give you even better advice as avi_0, avi_1 implies a bad DB design.
-
In your case I would go for the Abstract Factory or the Registry these are more flexible then your current designs.
-
Since you are so keen to keep it all centralized you can either use an Abstract Factory or a Registry. The Abstract Factory going something like this: class ASF_Factory { public static function getConfig() {/*code*/} public static function getDb() {/*code*/} } In your application you would use this like: $confg = ASF_Factory::getConfig(); $database = ASF_Factory::getDb(); This is more specialized then a Registry which is more generalized: $config = ASF_Registry::get('Config'); $database = ASF_Registry::get('Database'); Both inject the dependency and hides the real implementation of your Config object and Database which means that when at some point you want to switch your implementation of either the Config object or the Database object you can replace the lines of code in getConfig() or getDb() with the new object without you having to change any application code or create bugs. However both of course impose a global object and a hard coupling between ASF_Factory or ASF_Registry and the calling class since it doesn't necessarily need the ASF_Factory and ASF_Registry.
-
return $config = 'Config Var'; is the same as return 'Config Var';
-
That's because you decided to listen to the less experienced person while thorpe gave you the answer: class MyObjectThatAlsoHappensToInteractWithADatabase { private $db = null; public function __construct(Database $db) { $this->db = $db; } } Another option you could opt for is to use a factory: class MyObjectThatAlsoHappensToInteractWithADatabase { private $db = null; public function __construct() { $this->db = AppAssetFactory::getDb(); } } That saves you the trouble of having to pass $db all the time.
-
+1
-
Show us the code where you call ::authenticate() with the username and password. PS You may want to brush up on your OO since their is nothing OO about your code. 1) You use globals 2) All your properties are public 3) Every single method is static You could have saved yourself the trouble of having to write "class" everytime and just wrote procedural instead.
-
passing multiple function in codeigniter uri segment
ignace replied to linux1880's topic in Frameworks
Please read the CodeIgniter manual. As it contains answers to all your questions regarding CodeIgniter. -
Nice, I really like the way it loads the next page (and tells you the page you are on) when you scroll down
-
Indeed, you will learn more by what you teach then any other forms of learning. My colleagues still don't understand why I try to give a presentation almost every once a week.
-
It doesn't matter how you turn it, the answer remains: NO. Using an array to store information like configuration variables and languages remain a popular technique among programmers. Passing this array around limits your program to only an array to store this information while at some point you'll realise that using an array to store languages is unmaintainable yet you used the array everywhere in your application so you have to go through the horror of finding and removing unused translations. Using a class instead gives you more flexibility as illustrated below: interface Translator { public function get($variable); } class ArrayTranslator implements Translator { public function __construct(array $array) { $this->_array = $array; } public function get($variable) { return $this->_array[$variable]; } } In my application I use it like: public function setTranslator(Translator $tl) Now i have come to the point where I realise that using an array to store my translations was a bad idea so I'm switching to Gettext and use the awesome tool POEdit to sync my translations. class GetTextTranslator implements Translator {/*actual code omitted*/} In my Factory I replace it with my new GetTextTranslator: class ApplicationFactory { public function getConfig() { if (is_null($this->_config)) { $this->_config = new ArrayConfig(include 'path/to/config.php'); } return $this->_config; } public function getTranslator() { if (is_null($this->_translator)) { $this->_translator = new GetTextTranslator('path/to/gettext/directory'); } return $this->_translator; } } I switched my entire application from using an array for translation data to gettext in one single line of code. How long would it have taken you to do the same using global $config or global $translate? Maybe it wouldn't have taken you too much time, if the code was properly written, but can you also switch between languages on the fly without leaving too much of a mess? $translate->_('Hello'); $translate->_('Good morning', 'fr'); // this should always be in French