Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Posts

    1084
  • Joined

  • Last visited

  • Days Won

    126

Everything posted by Antonio Conte

  1. Part of what makes being a student pretty awesome. Hope you get some more time on your hands soon.
  2. Number 3 is correct. Nothing to get confused about. Calling cookie() is nothing more serious than starting a session and adding a key => value pair. header() can even be called inside your own functions, or be applied login to. Don't over complicate things here. If you are in doubt, do a quick test. It takes less time and will give you confidence. Sometimes brute-forcing solutions is a good thing.
  3. New minor annoyance. Could you make the logo on you YII sub-domain website link to your main site? Currently, there is no way to "go back" to your main domain. It feels very unnatural as this is how it works everywhere else, including on this forum.
  4. I would double check your config file. Read the explanation there one more time. Pretty sure that's the problem. (I don't know this time)
  5. He said output, as in using print, echo or displaying HTML. To explain WHY, the server can use the header() call to set content type. For that reason, you cannot call header() once anything is displayed. To illustrate the point, this would not work: <?php header(); // Some call here ?> Notice the line break before the PHP tag? That is considered content. Therefor, it won't work. BEFORE you output anything to the browser, the header call can appear anywhere.
  6. The YII book requires sound knowledge of PHP in general. You should be able to figure out the requirements for yourself for a book on this level. A this point, code is not snippets or chunks of code, but a modular set of classes tied together by the Model-View-Controller programming pattern. I suggest you re-read some of the theory about that, as it should be pretty obvious what's missing with the right knowledge. Get the basic principles down before anything else. You cannot really use software like YII without those.
  7. It should all be pretty simple. Don't worry about database info as you can simply change config files in your scripts. The trick is to export all tables found in each database instead of exporting the databases themselves. That way, the name of the database won't really be an issue. Most host won't even allow you to import huge portions of data at the time, so important tables should be easier than importing databases, really. I have moved to other hosts a couple of times. It feels very scary, but I can assure you it'll work just fine.
  8. I searched for the title we used in my university course. Upon that, I found a video series you can watch for free. It's found on iTunes, but I bet you'll find it on vimeo/Youtube/similar to. The book we used is Data Structures and Problem Solving in Java, by Mark A. Weiss. I think it was a pretty good book on the subject, while some parts could definitely be improved upon. It will teach you Big O analysis, several search/sort algorithms, pretty much all data structures and core coding concepts including Iterators, Comparators, Generic Type (You need to know this for extending main parts of Java in a good way), good exception handling, private classes, advanced object scoping, recursion, static classes and functions, etc. As this is pretty much my only source for learning these concepts, I can't really make comparisons. You should, however, be able to understand this concepts, when to apply them, and how to implement them. The book is often starting out with simplified versions of a concept, and improves upon them though the chapters. Therefor, you can't use it as a straight reference, but need to make sure the implementation suits your need. As an example, three structures are seriously improved upon as the pages fly. The book requires a great understanding of basic-to-advanced object-oriented concepts, and you need to implement the solutions themselves to make the information stick. It's not by any means an easy read-though, and requires time and dedication. It has very good rating on Amazon, with 5 stars being the majority by a mile. As a head up, I would ignore much of the thesis and proves in general when it comes to this kind of stuff. It's not really relevant unless you want to do research mathematically/look for improvements on the algorithms. The important thing is to understand the concepts, being able to use them yourself, and understanding when to use them. That way, the things you learn about data structures and algorithms is pretty language agnostic, and Weiss also says this himself. You should be able to use these concepts in other languages like C# without problems, with some extra research and information about the languages core libraries. In the end, you'll know very much about how Java works. Hope that helps you out. Edit: Some video sources: - http://www.youtube.com/user/MIT - http://video.mit.edu/ Edit: Algorithm analysis series: (Skip to 17 min) - http://www.youtube.com/watch?v=JPyuH4qXLZ0&list=EC8B24C31197EC371C
  9. It compares all values in the array, but that happens internally. This is a pattern called a compator, and is used to compare collections structures like this PHP array (The array structure implements an Interface that makes it Comparable for a Comparator). To use more known examples, the reason why you can use a while loop on a MySQL(i) result object, is that this structure is built on a pattern called an iterator. This is also why arrays support foreach statements. (You can build this into your own classes) This pattern is often tied to lists of objects in other languages. Let's say you have a Person class. A PersonList would be a class that handles a list of Person objects (Using an array internally). This class can have methods for looping, adding, removing, sorting and a lot of other things. Such classes are called a Collection in other languages, and is a definition for lists, (that's normal arrays in most languages) linkedLists, stacks, queques and other fun data structures, including Hash maps (associative array keys are implemented as a Hash map). In PHP, all of these data structures are defined as ARRAY........ Let that sink in. The point here is that arrays in PHP is not arrays as you find them in other languages. That is not all bad, and also some of the reason why PHP is so awesome at times. The problem is that it makes it very hard to understand a lot of concepts for PHP developers as they don't understand the data structures strengths and weaknesses. Because we "have it all", very few developers has to think about how sorting, iterating and CRUD operations actually work. The reason why your examples work is because of this. The standard, built in internal way of ordering arrays is by a method most often call compareTo() in other languages. This method could be implemented in the Person example class of ours through an interface often called Comparable. When that is done, the PersonList can easily compare each Person found in the list and thus sort the array of Person objects. What you basicly do here is to say that PHP's Array structure (A PersonList) should compare all keys called name found in an element (A Person), using either the standard compareTo function defined in the Element or a function you define yourself. (And that function then takes the job of the compareTo function instead) This is both pretty advanced and pretty simple stuff at the same time. You cannot really understand all this at once, but that is approximaly how it should work. I cannot fully gurantee that's how PHP has actually implemented it, but these are well known patterns in object oriented programming. It can be defined as theory as much as implemented in practice. Once recommendation is to read about data structures if your interested, but if not then just take my word for it. Don't try to understand your toaster, just learn how to use it. Edit: Sorry about the poor English here, might clean it up a bit tomorrow. Been a great christmas with family, good food and a local liquor called "Akevit". (Aqua vita - water of life) It's a scandinavic speciality liquor that's great with fat food. Try it if you ever visit Denmark, Sweden or Norway. We take great pride in it, but mostly drink it around chirstmas time.
  10. Do you use JPEG or PNG here? The last argument for imagejpeg() will allow you to set the image quality. The standard is 75, so raising the number will improve the quality. The reason for loss in quality is that the algorithms used in GD are bad compared to the ones in Photoshop. (that's their job) Writing good compression algorithms is tricky. You can switch to PNG, but it will store larger files. Hope that helps.
  11. The trick is not to declare $errors = array(); Using $errors[] = 'message'; will also create the array if it does not exist. That way, $errors will only be an array if an error message is set. Else, it will be null. Generally, I would instead use empty($errors) to check, but That was not the task here.
  12. You can assign keys to a not yet existing array in PHP. It will then create it for you. (From PHP 5.3 or thereabout.) Do you have enough to solve the problem now?
  13. Ok. I can see a jumped to a conclusion too soon. Sorry about that. Regardless, the problem is that you are missing a learaar model. You call learaar::findByAttributes() in you UserIdentity class, but it does not exist. The guide does not teach you have to implement the model part. More info here: http://www.yiiframework.com/doc/guide/1.1/en/database.ar It should be pretty straight forward to implement.
  14. This is the problem. PHP cannot find your file. In the feature, do a search on the error message as it will often explain what's wrong. (The message kinda does too) This is a standard coding mistake and not related to YII per se. Make sure the file name is spelled correctly and has correct case.
  15. Haha! I thought it was pretty weird the solution wasn't working. I thought it might have something to do with YII's active records implementation using some sort of reflection like behavior (on columns), but that would not really make sense; Why not offer the possibility for aliases? It would make no sense, as this is pretty much required functionality. (I considered diving into code again) Not to rub it in, but consider doing to step by step development next time. If you had tested the functionality before trying to implement a full search function, you'd know the problem right away. A simple mock-up using GET and print_r() on the result would have done the job. Lot's of interesting problems you have had lately. What are you working on here, if you are allowed to elaborate on it?
  16. It's the main rule. No need to declare it. This is why it works to go to domain.com/index.php or domain.com and still see the default screen.
  17. I would guess it is because the actual expression is an empty but still a valid regular expression. (started and ended by a Char '/') As a consequence, I guess everything is a match, and it will then split on any character. While I guess this is the functional behavior, I cannot explain you why that would be. The second example on preg_split() in the manual uses the same approach, btw.
  18. Ok. A easier solution could be to split the full name searched for, then compare parts to firstname and lastname instead of combined. Simplest thing that comes to mind.
  19. According to a Stack Overflow answer, the way you did it the first time should really work. The question is, did you put the method in the User Model or in the Search Model? From the looks of it, it's in the search model. Try placing it in the User model instead. The only reason I see for this failing, is that the Active Record of YII looks at table definitions and compare it with public attributes set. Maybe you need to remove that attribute and let YII use the method declared instead? I don't really know if this is any problem, but give it a try if you meet troubles.
  20. Yes, I expected it might have something to do with that. Glad you solved it.
  21. Seems like a encoding problem. Try applying something like mysqli_set_charset('utf8'). I would also not run mysqli_real_escape_string on the hashed result. After hashing, that won't really be a problem anymore. Remove it. I don't really understand why you don't simply change to a char or varchar type instead. I understand the potensial save in data, but is it really worth it if it gives you all this trouble? One last suggestion: Sure your input is not truncated? Try generating a hash with the function, echo it to screen, then save it using something like phpMyAdmin. Then you can make sure that is not the problem at least. http://php.net/manua...set-charset.php
  22. It could return 0. It will do that in my example, as an empty string is in position 0 in the array. (first and only element) As 0 equates to false with != (because of type cast) it would SEEM like an error occurred even though it should not. That is why I used the example I did. You should try running the code. I even provided you the output of each comparison. What you should learn from this: Use the value and type comparison operator (===) whenever a function is marked "not binary safe" in the manual, or whenever you NEED to enforce type. I NEVER use normal value checks anymore unless I have to. Too much potensial for fuck-ups in the code, really. That operator is the reason for many a bug found in PHP, and the use of it should die...
×
×
  • Create New...