Jump to content

OldWolf

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

OldWolf's Achievements

Member

Member (2/5)

0

Reputation

  1. Howdy all, I'm working on a website that needs to support several different languages. There is a good chance of a lot of load on the website, so I'd like the design to be fairly sleek. What is the best method I could apply for different languages? Here's my intial thought, feel free to explain why this is a bad idea. Class lang: - stores the lang strings in the simple format of array("lang string goes here" => "translation goes here"). - Loads new strings by a method that gets files and merges the stored and new arrays. Within the files - $lang->i18n("Translate this string");
  2. So you would recomend I follow their lead with that? If I don't go that route, would a left join select from the two tables be the next best approach? Thank you! James
  3. Howdy all, I'll say right off the bat that I can use mysql very proficiently when it comes to the basics, but I've never really pushed myself to learn much beyond that (even so much as joins), so I may be missing something incredibly obvious here. Here's my basic problem... at a lot of points around the site, things will be credited to a specific person. An example might be a post (in the form of a blog of sorts) on the index page. It will indicate not only who wrote it, but what their user level is. Originally, my plan was to put only the userid into the table for each row, and when collecting posts, I would just get the user's info out of the user table using their id. However, I was looking at how phpbb does it, and I see that they actually include the username and color (the color ends up being about equivalent to the userlevel) in the actual row for the post. If a user's color is changed, they perform an update on all the rows containing that user's id. Now assuming a potential of a million users (yea right, lol), what's the most efficient way for me to go about this? Put the username and userlevel in the post table? Select it after I get the posts? Something else I'm not thinking of? Thank you! James
  4. Thanks for your help. My solution came together like this: I have a class that stores the form already. I created a new method which accepts an array full of fields like described above. The method goes through each one, and sets it like so: $this->fields[$key] = array( 'type' => (isset($value['type'])) ? $value['type'] : 'none', 'lang' => (isset($value['lang'])) ? $value['lang'] : '', 'list_lang' => (isset($value['list_lang'])) ? $value['list_lang'] : '', And so forth. The ternary conditionals keep the code simple, but assure that each field as a value (either the default or the one passed), and no extra fields can be added because it only handles the ones I list. Thanks.
  5. Hehe, no, I wasn't very clear... sorry. What I mean is that I want specific keys to be the only ones in the array... no more nor less. Does that make more sense?
  6. This is going to be a strange question, but other than using a function that validates it, is there any way to force an array to fit a specific format? This job seems a bit small to create a class for, but maybe that's my best option? The job wouldn't be a whole lot more complicated than the example below. These individual arrays would be making up one larger array for a form... but I want each smaller array to have identical formats (I might not be the one writing every one of them). An example: I'd like to make sure that all the arrays have the following 5 keys (the real thing contains several more keys, some with their own arrays, but you get the point): Array( 'name' => '', 'type' => '', 'value' => '', 'required' => '', 'max_chars' => ''); Just to give background, all of the arrays are presently in an array, which are contained in an external file. The idea is that several files can reuse this same format, so that modifications are easy.
  7. Wow, guess I wasn't too far off. The idea of returning the array from the file is perfect, and close to my set up which should make it easy. That's what I think I'll go with. Thank you.
  8. I believe the above might be off... "to" should be larger than "from" when turning it into a time stamp. if ((strtotime($to) - strtotime($from)) > 864000) { echo "EPIC FAIL!"; }
  9. Background: Whenever I write a package of some kind intended to be included into a bigger piece, I set up a constant for the path to that package, so that when I include files within the package, I can do PATH . 'included.php', when it's located in the root of the package. Problem: The package I'm working on right now will not always be in the same place, so my constant has to be figured out dynamically. Essentially, what I'd like to do is get the path from the original file to the included package. I know there's a simple solution here, but I'm so darn sleepy I just can't think of it! Thanks!
  10. What he posted would do just that... you just need to apply the form before it, and then collect the name out of the submitted post and set it to the $name var.
  11. I feel like setting the array in another file, and depending on that array from a require into a method is very hacky. I'm not really sure how to go about it, that just doesn't seem like a dependable way to do it.
  12. Ok, here's my set up: I have a class that holds all my configuration settings. What I want to do is have a method called "load" which will load up a file full of configurations. $config->load('path/file.php'); My question is, what's the best method I could use for load, and how should the config file be formatted accordingly? Everything I've tried has seemed pretty hacked. Here's an example of one of my ideas... but I'm not fond of it: public function load_file($file) { require_once($this->path . $file); $this->entries = array_merge($config, $this->entries); return true; } And the file: $config = array( 'use_db_sessions' => true, 'allow_active_sessions' => '5', 'db_session_salt' => 'This is some yummy salt!', 'guest_id' => 0, 'cookie_path' => '/', 'cookie_domain' => '', 'use_persistent_login' => true ); As I said, very hacky... is there a cleaner way to do this. Please and thanks.
  13. Thanks! I'm not sure I'm going to use exactly that class, but I will work with my class based on it. OldWolf
  14. I suppose my method does have the disadvantage of not being able to overwrite a set value, so I'll have to unset and set values each time. That could pose a problem down the road. If I do use his approach, I'd probably want to universally use a similar system with all of my objects (so I end up coding in a uniform way). Other than having to be very careful what the returned value gets set into (so that I'm not accidentally making changes to the object value on what I wanted to be a temporary value), could you foresee any problems with this? Thanks again!
  15. Thank you for the idea! Just today I had a great realization that seems to be working perfectly: public function __set($key, $value) { $this->data = array_merge_recursive($this->data, array($key => $value)); } This achieves what I want with the following example code: $m['lang'] = 'Navigate!'; $m['type'] = 'header'; $m['order'] = -100; $tpl->menu_blocks = array($m); $m['lang'] = 'Navigate2!'; $m['type'] = 'header'; $m['order'] = 5; $tpl->menu_blocks = array($m); This puts the blocks into a numerical array under $this->data['menu_blocks'] = array(0 => 'menu block array', 1 => 'menu block array2'); It also lets me set single value entries by just doing the $tpl->key = 'value'; which will be set into $this->data['key'] = 'value'; Thanks for everyone's help!
×
×
  • 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.