Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. If your class is named like this: namespace Foo\Bar; class Bat {} And it is located in app/library/Foo/Bar/Bat.php. Then your include path should be: set_include_path( realpath('app/library') ); So that when PHP looks for Foo\Bar\Bat it will find it in app/library/Foo/Bar/Bat.php. Change your directory structure or alter the include path so that it matches with where your classes live.
  2. Wherever you wrote: [exec]echo include('2.php');[/exec] Change it to: [exec]include('2.php');[/exec]
  3. [exec]include('2.php');[/exec] the 1 is because include returns true, echo true; prints 1 on screen.
  4. It's a made-up example to communicate a point. The code is untested and it's not advised to just copy-paste it and put it on your live website due to the gaping security holes in the code. If you take a look at the code for index.php you'll notice a missing } after "No users found!"; The same for profiles.php after "No user found by that name";
  5. Something like this? // so if the value THISVALUE is the only capitalised value then the if statement should return false // .. but fail if all are lower case (or if THIS VALUE is the only capitalised value). $test = false; if (preg_match_all('!([A-Z]+)!', $string, $matches)) { if (count(array_keys($matches[1], 'THISVALUE', true)) === 1 && count($matches[1]) > 1) { $test = true; // So, if THIS VALUE exists as well as other capitals, then it should return true } } if ($test) { // THISVALUE existed more than once }
  6. https://github.com/kriswallsmith/Buzz Your directory structure should look something like: vendor `- Buzz `- Geocoder autoloader.php In your autoloader then should be: set_include_path( implode(PATH_SEPARATOR, array('.', realpath('vendor')) );
  7. That is due to php being unable to locate the class. Make sure you have something like this in your bootstrap file: set_include_path( implode(PATH_SEPARATOR, array('.', realpath('path/to/library')) ); spl_autoload_register(function($className) { $className = ltrim($className, '\\'); $fileName = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; });
  8. You can develop your website locally, but those changes will not be visible to online users until you FTP them to your server. http://www.apachefriends.org/en/xampp.html If you are looking to make parts of your website offline available, you can use this: http://www.catswhocode.com/blog/how-to-create-offline-html5-web-apps-in-5-easy-steps
  9. The code I provided was an example and untested. It's not advised to just copy-paste it, since I have no idea in what context it is being used.
  10. $r = bcmod(bcpow(254, 187), 319); // 100 Edit: damn 30 seconds late Edit: Actually echo bcmod(bcpow(254,187),319) = 100; Returns an error
  11. I sponsored your "Philip for Admin" campaign yet that bought me NOTHING!
  12. Vote?! What vote?! It's a damn dictatorship here! XD P.S. Congratz jesi. You must have friends in high places.
  13. .<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a> Unless I am mistaken that is HTML.
  14. I need some help in regard to class design and sync between DB and XML. The XML looks like: <data> <offices> <office>* <projects> <project>* <property> <property>+ <employees> <employee>* </data> Legend: The tags marked with * means they can occur 0 or more times. Those with +, 1 or more times. The XML is deeply nested (there is no 1-to-1 mapping with the DB). Each of these tags have an <id> tag and "foreign keys" for example a property tag can have an office_id tag and a project_id tag. I need to create a class that reads that XML and syncs it with the properties, offices, and projects in the database. It should also be possible to sync it from the database back to the XML. My frst idea went like this: class FatXml { public function findProperty($id) {} public function findOffice($id) {} public function findProject($id) {} public function addProperty(Property $p) {} public function addOffice(Office $p) {} public function addProject(Project $p) {} public function removeProperty(Property $p) {} public function removeOffice(Office $p) {} public function removeProject(Project $p) {} } As you can imagine this leads to a lot of code in the FatXml class, recently a new tag was added (employees) which means even MORE lines of code. The mapping alone from leafs (XPath) to setters is hundreds of lines. Does anyone have experience with this sort of thing? Any pointers? Another idea I have been playing with is to let the FatXml object be a facade which encapsulates several smaller "parsers": class FatXml { public function __construct() { $this->list['properties'] = new PropertyParser($this); $this->list['offices'] = new OfficeParser($this); $this->list['projects'] = new ProjectParser($this); } public function findProperty($id) {} public function findOffice($id) {} public function findProject($id) {} public function addProperty(Property $p) {} public function addOffice(Office $p) {} public function addProject(Project $p) {} public function removeProperty(Property $p) {} public function removeOffice(Office $p) {} public function removeProject(Project $p) {} public function parseAll() { foreach ($this->list as $parser) $parser->parse(); } } Which is I believe better because when a new tag is added, I only need to create a new class, and add it to the list: addParser(ParserInterface).
  15. You can inverse it. So you don't have to indent like mad. public function _remap() { $user_id = (int) $this->uri->segment(2); $registration_key = $this->uri->segment(3); if (!((is_numeric($user_id)) && ((isset($registration_key)) && (!empty($registration_key) && (!is_null($registration_key)))))) { $message = 'One or both parameters were not entered!'; } else if (!(($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))) { $message = 'The parameters do not meet the validation criteria!'; } if (!$this->users_model->is_registered($user_id)) { $message = 'The user specified does not exist in the database!'; } if ($message) return $message; $user_status_id = $this->users_model->get_user_status_id($user_id); if ($user_status_id != 1) { $message = 'The user specified is already activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>'; } else if (!$this->users_model->check_user_registration_key($user_id, $registration_key)) { $message = 'The registration key did not match the user specified!'; } if ($message) return $message; $this->db->trans_start(); if ($this->users_model->change_account_type($user_id, 2)) { if ($this->users_model->erase_registration_key($user_id, $registration_key)) { $message = 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>'; } else { $message = 'The registration key failed to erase for the user specified!'; } } else { $message = 'The user specified was not able to have his account changed!'; } $this->db->trans_complete(); if ($message) return $message; if ($this->db->trans_status()) { $output_array = array('error' => FALSE, 'message' => 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>'); } else { $output_array = array('error' => TRUE, 'message' => 'The user was not able to be activated. The account specified was not able to be changed into a user!'); } return $output_array; } Further more I think the HTML should not be in the _remap function.
  16. You overwrite the object: if ($result->GetUnsecuredLenderResult->Success) { // $result === object $result = "A"; // $result === string PHP is dynamic typed which means that it's type is defined by whatever you assign it. http://php.net/manual/en/language.types.type-juggling.php
  17. They are enabled by default in PHP 5.4+ I consider it good practice to use them in view/template files, bad in all other instances, makes it more readable. http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
  18. Well in the house example I was thinking of breaking it down into Kitchen, Bathroom, Bedroom, .. which would all become part of a giant composite tree (House as parent) but before going down that road I wanted to see how the current design played out. I don't need all the data all the time, and I also only load whatever is required at a particular point. Actually it's a proxy (wrapping a DAO) so that if I ever would need extra data, I can still get it. I should also mention that the design currently works on 2 different schema's. DB and XML. 3rd party sources send us an XML which are translated to the proper objects and is synced between the XML they send us and the DB.
  19. There are some use scenario's where getters/setters are not a real option like when a class would hold over 1024 properties that are changed by users (or the system itself) in different parts of a system which is common for big data projects (like for example all attributes of a house). If anyone has any pointers for me on these scenario's, please share them with me as currently it all goes through $o->set($name, $value).
  20. Those constants are DB specific thus I see no reason why they should be excluded. You can still access them, all you need to do is prefix ClassName::SOME_CONSTANT or if you have an instance of the class $class::SOME_CONSTANT. Then the explicit use of mysqli_* inside your class. If you only ever are gonna use mysqli_* that's fine otherwise use the Adapter pattern and pass it the "driver" your wanting to use. At the very least I would create an interface for the SQL_Conn class so that it becomes interchangeable in your code and not as tight as a knot. function doSomething(SQL_ConnInterface $conn) not function doSomething(SQL_Conn $conn), the latter is tightly coupled to the SQL_Conn class while the former allows me to implement the SQL_ConnInterface and provide my own implementation. Upgrade your skillset, and make your classes follow the PSR standard @ https://github.com/php-fig/fig-standards/tree/master/accepted. There is a lot of code, and some methods body go way beyond screen height, some refactoring will help to make it maintainable, breaking the class up into some smaller parts with a distinct responsibility may help, for example QueryBuilder has nothing to do with a SQL Connection, you can easily build a query without having a connection to any database, all you need is to know the platform you are building it for.
  21. department (dpt_id, dpt_name, ..) group (grp_id, dpt_id, grp_name, ..) person (psn_id, grp_id, ..) schedule (sch_id, sch_date, psn_id, sch_comment, ..) This schema is much easier to work with and does not impose the same constraints as the previous would. Meaning that you will have to enforce these in your app. instead.
  22. Own group or groups? 1 department has 1 group or 1 department has many groups? If the former then you can just add a dpt_id to the groups table (or a grp_id to the departments table, either way works). If it is the latter then you'll need a department_has_group table with (dpt_id, grp_id) as columns. You will have to populate this from your application and store it in the schedule. Afterwards you can just query the schedule to find the person's on call for that week. http://en.wikipedia.org/wiki/Cron Because he won't be in the schedule table in the week of 18 jan 2012. If you want to be able to make these specific lookups the schedule table will need to be modified to use a DATE instead of (week, year). I don't have the time now but I'll create a new schema matching this, this evening. Yes, for each year. Using a cron you will populate the schedule every week for the next week/month/year so that everyone knows there schedule in advance. Are there only 4 people on call each week? Know that when this changes you'll need to create a new group to be able to assign a 5th person. After the things you told me so far I think the current schema does not match this, when I get home I'll have another look at this and have a stab at a better schema.
  23. So you have an open-source game on YOUR webserver. Where you have access to THE DATABASE. You want to create a bot that does some stuff so that you can gain... resources?! Run this in phpmyadmin: UPDATE players SET gold = gold + 99999999, iron = iron + 99999999, .. WHERE id = your-id Refresh the page (or logout/login) and voila 99M gold, iron, ..
  24. group (grp_id, grp_name, ..) person (prsn_id, prsn_fname, ..) Straight forward tables to hold groups and persons. Does each department have it's own groups? Or are group names shared, but depending on department filled by other persons? person_in_group (prsn_id, grp_id) This table will hold which person is in which group. A person may be part of multiple groups, if this is untrue, then add grp_id to the persons table and create a unique key as a reference point for schedule to verify a person is indeed part of a specific group. schedule (week, year, grp_id, prsn_id) This is the harder part, (week, year, grp_id) is the primary key of this table so that the same group id can't be assigned twice for the same week, as a bonus this means only 1 person from a specific group per week. The (grp_id, prsn_id) is a reference to person_in_group (or person table depending on your setup) and must match a row there. A real date (meaning a day) or a week? This is addressed in the schema unless multiple persons from the same group may be in rotation for a specific week. I need some more information what you mean by these numbers. I think this should be filled with a cron or something into the schedule table. This should be handled in your application so that all forward queries no longer have this person assigned. Historical data remains untouched. Simply change the prsn_id in the schedule table. As long as there is only 1 user from each group assigned during a week. This is just a first draft, there is still a lot of fog concerning what you want to do and how. Explaining clearly what you want to do and how and why will help us to better help you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.