Jump to content
Larry Ullman's Book Forums

Jonathon

Members
  • Posts

    1064
  • Joined

  • Last visited

  • Days Won

    55

Posts posted by Jonathon

  1. Glad you sorted it. Yes you're totally right, anyone can read books upon books about programming and follow it (more or less), but I personally find that I can't progress unless I try to put it into action on my own or use a combination of what I've read to try and provide a solution to whatever I'm trying to do. Most solutions I find, I know the code behind them, it's just i'd never have thought to do it myself, whcih I suppose is the battle. Best of luck with your project anyway :)

  2. if (preg_match('/skill_item\d{1,2}$/', $value)
    

     

    Here $value is equal to the value set in the form. So that validation will always fail. Because the value will be taken from this

     

    <option value="2">
    

     

    ie the preg_match is checking to see if preg_match('/skill_item\d{1,2}$/' === 2

     

    The $key will be skill_item4

     

    so something more like this:

     

    $skills = array(); // empty array to store values of multiple skill_item questions
    
    foreach($_POST as $key => $value) {
     if (preg_match('/skill_item\d{1,2}$/', $key)) { // select element is skill_item field
    
    $value = (int) $value; // or further validation if you wish.
    
     $skills[$key] = $value; // will generate an array like Array ( [skill_item4] => 5 )
    
    } else {
      echo 'Wrong field element';
     }
    }
    

     

    It isn't perfect code but it may help you to see how it works

  3. Currently $name is equal to a literal string. You can just use a regex if you want to.

     

    $data will never be created unless $name is equal to 'skillLevel%', which it won't be.

     

    Regex's are a bit more intensive on resources, perhaps you could use the substr to achieve confirmation that skillLevel is in the string. Thinking ahead, perhaps it may be best to name your fields skillLevel_1, skillLevel_2 then you could explode() it to return the 'skillLevel' part, which would allow you to continue the process and also you could know the number of the skillLevel.

     

    Does that make sense?

  4. Why don't you concentrate on your own work rather than judging someone on what they can't/shouldn't do etc, when you don't even know anything about them.

     

    Incredibly constructive Edward, you should have said you had 7 JavaScript books!!

    Which brings me to my next point, if being as you have 7 JavaScript books, why do you need a cookbook on JQuery? (Rhetorical question)

    As you may have noticed I stopped replying some time ago to your private messages, this will translate over to the forum also.

  5. I would say that you can't/shouldn't try to use a javascript framework without being somewhat clued up on javascript. It's not a case of reinventing the wheel, although I understand why you say to just use jquery. But to use it well and if you want to be able to use it on multiple sites with multiple plugins, that the cookbook possibly won't cover. Then you try to get a good understanding on js. Especially if you want to start using things like ajax.

  6. I apologise for the crudeness of this example. I'm using the workbench on a personal project and I've plugged in all my data and allowed the workbench to generate the relationships, which is fine. but what is the difference between relationships that start

     

    -| |---------

     

     

    and ones that start like

     

    -|-|----------

     

    is one identifying and the other non-identifying?

     

    On a secondary note, I feel like most examples i've seen of your models Larry flow nicely in an almost clockwise manner. I'm finding that mine has 5 tables that all feed into a central table, this central table is the hub of the displayed information, but there is a fairly large proportion of the central table that is built up from P.Keys in the other tables. Does this mean that my design is poor at a guess? I realise that there isn't a great deal of information for you here, but I didn't want to bombard you with huge swathes of information.

  7. Yeah, this is say an id of one table that appears in other tables to reference data. I tried quite a few variations of the the Foreign key command, including yours, but sadly they didn't work :-(

    So it looks like manual updating of the models, which isn't too bad (I don't think, I know you cover it in your guides), so it would have been nice to get a good DB down and Yii just do it for me. Maybe in 2.0!

     

     

    Thanks Larry :)

  8. Hello!

     

    I have a foreign keys that are represented in multiple tables, is there a way to get Yii to recognise more than 1 foreign key comment when generating relationships.

    I've tried so far

     

    CONSTRAINT FOREIGN KEY (id) REFERENCES r_detail(created_by_user), mentions(user_id)

     

    Yii just seems to take the last table(column) as the relationship, regardless of what precedes it.

    Is it even possible what i'm trying to do? I don't know

  9. Move towards objects. That's really the way to go. If you think you have to many variables, you are probably right. The problem though is NOT speed or memory, because that's cheap with variables. It's that your code gets hard to maintain and understand. You should know that an object is really not taking up more memory than your common string or integer. Objects are not these huge, heavy things. It's the algorithms for sorting, filtering and validation (of array structures) you'd want to be critical about.

     

    As I mentioned to someone else. I created 300 000 Card objects (yellow cards in football) which itself holds a Player and a DateTime object. How much time did that take? 0.3 seconds for the instantiation. How long did this take to print (echo) to screen? About 1.8 seconds, (which is to long) but who would need to create 900 000 objects (1 card, 1 player, 1 datetime) in one PHP-script? The reason why I tell you this is to understand that objects are cheap too. Learn object-oritented design, and your code will get a lot better FAST.

     

    I would really recommend this book: http://www.amazon.co...s/dp/1430210117

     

    It is a good book! :D

  10. Most clients won't understand rhe difference and probably won't care. OOP is about re-usable code, so I would suggest that you don't make OO classes just for one project and then try to re-use them. I'd make a series of classes as a framework and then use them in projects if appropriate - then you could argue it is a service to the client as you've already done the hard work, all you're doing is passing details to the objects.

    • Upvote 1
×
×
  • Create New...