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. You helped me some time ago by something similar for car makes and models. I solved this by saving the data as JSON, but it could obviously be generating executable PHP arrays to. My solution was to save the info in a database, then write to this file on updates/inserts. I would think something similar could work for you as well. I'll think about it some more if not, but I don't really think I would find a better solution.
  2. Have you tried validating the XML? Is it schema based or not? Are you sure the XML documents finds its scheme if so?
  3. I would bet it is explained. This is really information a quick google search would give you thought. Tripple comparison performs check on type as well as normal comparison. Notice the HUGE warning on the documentation on stripos? That tells you that this function is not binary safe. This basically means that you must look out for values that will equate to boolean false. The most obvious (and seriously stupid) example is "", an empty string. The problem arises because this function returns boolean false on errors. There are in other words no way to know if an error happend or you got an empty String. The very simple solution is to also check for type. // Try getting the index of an empty String from array holding empty String (Result is 0) $result = stripos(array(""), ""); // Perform normal comparison (Result is "Error") echo ( $result != false ) ? "..." : "Error"; // Perform type comparison (Result is "Works") echo ( $result !== false ) ? "Works. Found at index: {$result}" : "...";
  4. Yes, I do study computer science. Thanks for the nice words. I like to life by the words of Albert Einstein:
  5. You have to dig into the source code of PHP mailer a little bit. This is what I found: /** * Callback Action function name. * The function that handles the result of the send email action. * It is called out by Send() for each email sent. * * Value can be: * - 'function_name' for function names * - 'Class::Method' for static method calls * - array($object, 'Method') for calling methods on $object * See http://php.net/is_callable manual page for more details. * * Parameters: * bool $result result of the send action * string $to email address of the recipient * string $cc cc email addresses * string $bcc bcc email addresses * string $subject the subject * string $body the email body * string $from email address of sender * @var string */ public $action_function = ''; //'callbackAction'; In other words, it will invoke a function upon $mail->Send(); You should store the result in a variable and print it for response purposes. It will give you general information about the mail being sent. As you can also see, this property says to look for "is_callable()" in the manual. I take from that they use a function like call_user_func() with your method name. For this to work, the function (or static function call) must obviously be declared (or required/called upon) in the same file. That is why you can see the function "callBackAction" above in your code. Do you have enough sources to get this to work now? Alternatives are placing this function below your controller definition or create a static "helper" class. I would go for this last approach, where you could also wrap this wrapper code. (Yo dog, we heard you like wrappers, so we wrapped a wrapper in a wrapper.) That way, it should be very clean: Lots of into on different ways to create small helpers/helper function and how to call them here: - http://www.yiiframew...-functions/#hh1
  6. Why do you ask these questions? Read the information in the link provided. It's all there. - It does not matter. That kind of data storage is allowed. - Speculation, but I would think only serious violations will be affected. The goal is to protect the end user, not ruin the Internet. - Yes. You need to accept their cookie policy in some way if they user your private information. - Read the article. The only thing that matters is whether your business is directed at EU or not. As Norway is not a member of the organization that is EU, I can pay for hosting in U.K and forget about all this as long as my business is mainly for Norwegians. It is vague, but do you really think small businesses is the goal here? They want to prevent major companies like Facebook from selling the personal information of EU citizens. I don't really think they will affect your business at all, unless you do something obviously stupid. Use some common sense here. If your customers would be likely to react when told what you save about them, I would say that's a good indication. If they would most likely not, I would say you are on safe ground. No need to be hysterical about this. Again. Read the article...
  7. I would argument that settings fall into this category, given that the cookie is only created following an action done liberally by the user of course. The same argument can be made for a cookie created after a user clicks a "remember me" check box upon login. I may be totally wrong here, but the end goal is really to prevent a website from saving personal information without communicating why and how this is done. What do you think of the examples provided? Do you agree, folks?
  8. Weird. I cannot see anything in the manual that explains that. Non of the comments include header calls that uses newline ending either. I'm sure he explains it in the book if there's some special reason for this. (Maybe you just missed it?) Yes. Newlines are applied because of legibility. It serves no other purpose functionally. Another reason could, however, be because a file is supposed to be read with PHP or another language. You need some way to tell this reader where a line ends, or it will read everything as a single line. Text editors applies these to the text without telling us, but they must exist. Please notice that line endings may depend of OS, so it's not save to only look for "\n"s. ini_set('auto_detect_line_endings', true); The line above will normalize the line endings for you.
  9. I have to ask this: Does this really make sense? You are generating a whole XML file by PHP here. Could it possibly be done simpler? Have you checked out JSON? CVS? If you really need the integrity good XML can offer, then ignore this part. Look at your error message. Does the file exist? Is the directory writable? Some simple checks you have to do here. It says "problem creating file". It would indicate the file is not found for me. Do you like football, margaux, or is this just a project? Forza Juve!
  10. You first need to define the problem before you look for a solution. Generic help is hard to give you. Write down all functionality you need to implement such a solution before you start coding. It could for example be something like this: 1. Not authenticated users cannot view static pages. 2. User X could be allowed to watch page X, Y, Z, but not A, B or C. Should we do this using a white list or blacklist approach? The solution selected should be the simplest. If a user more often than not are ALLOWED to view a page, a blacklist might make sense. If only some of the X number of pages is available, do a whitelist approach. 3. Page E, F and G requires a certain access level. How do we solve this? From there on, we can start to define some generic rules. - If a user is not logged in, he is denied - We must check a blacklist/whitelist for allowed pages - We must check access levels This is a stupid example. I don't know what you need to implement here. However, you SHOULD use such an approach to define your problem. With a clear definition, everything is much more simple. It's also much more simple to help you that way. As a bonus, when a problem is clearly defined, you more often realize how you can actually solve the problem yourself.
  11. It's basicly the same thing as in PHP. There are some small differences though. PHP has a MySQL library integrated alongside PDO and the MySQLi extension. In C#, you have to download a library called Connector/NET version 6.1 and import it into your project. This is the same as when you use PEAR/similar to download extensions for PHP. Once this is integrated into your project, you should build a class that handles all operations on the Database, including connection and CRUD-operation. This is a great tutorial by the looks of it. I've never done this in C#, but I have done so in Java. It looks like a well written article. I did a serch for "C# mysql" to find it. One important thing to notice. Notice the "Adding Reference and Creating the MySQL Connector DLL from the Project". That is very important. Without that step, the users must have the Connector/NET version 6.1 installed to use your app. http://www.codeproje...nect-C-to-MySQL Ask questions if you need help. I'm not very familiar with C#, but I should be able to help out anyhow. A C# forum would really be my best guess if you need real help.
  12. Glad you solved it! Was not my point to go all professor on you. Nice to offer an apology. I'm sorry too. No hard feelings. I think this is a pretty clean and good solution after all. I'm sure you could solve this even more elegant than this, but for such a specialized case, I think it's very good. If you want to improve it, I would look into splitting some methods and adding a constant. Very small alterations, but the code is easier to follow now. You could also look into improving the controller ever so slightly. No need for the private staticController::setAkja for example. (As an object can use their own private properties) <?php Yii::import('zii.widgets.CMenu'); class XMenu extends CMenu { const STATIC_LABEL = "static"; protected function getStaticPage() { $ctrl = $this->getController(); if($ctrl->id == self::STATIC_LABEL){ return $ctrl->getAkcja(); }else{ return '/'; } } protected function isItemActive($item, $route) { // Check for static item if ( $this->isItemStatic($item, $route) ) { return true; } return parent::isItemActive($item,$route); } private function isItemStatic($item, $route) { // Make sure route is static if ( $route != self::STATIC_LABEL) { return false; } // Split route to parts $akcja = (explode('/', $item['url'][0])); // Make sure part three exists, then compare if ( ! empty($akcja[2]) ) { return ($akcja[2] == $this->getStaticPage()); } // Item is not static return false; } } ?> I have not tested the code above, so it depends on your own code working as expected. I added small checks to make sure $akja[2] exists, etc. If you should ever need to implement subdirectories here, look into the method renderMenuRecursive(). You'll understand quite quickly how it is solved.
  13. To clearify, this is what you want? Specify if I'm missing your point 1. You want to have "static files", not really related to any controller, located in the folder /static? 2. You need this implementation to work with a CMenu object, as you need to highlight URLs that should be considered static? Another way to do this would be to: - Define a ignore rule in your .htaccess file. Specify that calls to the "static" folder should not be routed by YII. - The CMenu is more tricky. I think this can be solved very simple. You define a CMenu trough Items, right? This is what the manual says: You could provide a CSS class here, like "static". You'd then be able to style static items differently. If this solution is to manual, my first (tricky) approach might work: Look inside CMenu. It has a method call normalizeItems. It takes the items specified when calling CMenu, and work with them. This is how the logic for active items is done: if(!isset($item['active'])) { if($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item,$route)) $active=$items[$i]['active']=true; else $items[$i]['active']=false; } else if($item['active']) $active=true; The important test is CMenu::isItemActive(). You could write a similar test like isItemStatic() and set each item to conforming to the rule with: $items[$i]['static'] = true; - The next step is CMenu::renderMenuRecursive(). You can see a boolean check for "active" here. It looks like this and ads the $activeCssClass (swap with staticCssClass) to item[n]: if($item['active'] && $this->activeCssClass!='') $class[]=$this->activeCssClass;
  14. It should be "This is a forum". You should be able to comprehend that, but ok. That pretty much sums up why you are acting like a total douche bag. Why should we do the job for you? We can sure try help you find a solution, but don't demand it on a silver platter. Get some manners, please... I have provided you a couple of possible solutions. Hope those helps.
  15. You may try defending yourself by hypothetical questions all you want. I'm not buying it. It's not single phrases that is the problem here. The problem is that you demand an explanation to an undefined problem, and you don't even do that politely. Why should anyone invest time solving a problem for you considering that? Next, you did not even provide that link yourself, referring to what you may have tried. I would deem that as an obvious attempt at helping, even though you don't recognize it. This is an attitude problem... This is a book covering 22 books, with YII as the newest addition. Obviously, this is not the place looking for people that know YII by heart. Another reason to ask politely, as some of does people might understand the documentation while not knowing this beforehand. You harvest as you sow. Edit: Ok. I think you get the point. Here's several ways to implement the rules you want. 1.) Write a class extending CBaseUrlRule that implements these rules you want. Use this rule object in the controllers where you want this behavior. This is more elegant as the object will encapsulate the rules needed. 2.) Write an abstract controller holding these rules. All implementing controllers extends from this one instead. 3.) Alter the main CBaseURLRule class. Not recommended. 4.) Implement the same ActionMissiong method, but do it in an abstract controller, or even add it to the main YII controller. Ask if you need more help, but please ask nicely. I don't care if you think you already do. You are not perceived that way.
  16. "General advisory"? It's all there! Learn to talk polite to people. Why should I even care to help you when you behave like that? I know the answer, and it in the link provided. http://www.yiiframew...1/en/topics.url Figure it out on your own.
  17. Yes, it should be "player.player_id" as you said, not "player.id". A small error there. Thanks for the nice words, btw.
  18. They are clearly building a transformer, Jon. The phone will turn into a lean, mean, killin' machine when stolen. Think we all understand the main purpose with such an app, so no need to think of the term literally. I think your suggestion regarding "Find my iPhone" is really good. I found an article about similar apps for android. Good luck with the project. Keep us updated.
  19. This is a capcha library, right? Only thing I could find. This library requires the GD Image Libary. Is that library installed and enabled? If not, I have no clue.
  20. It's a work in progress. New parts will be released every so often. You can find a lot of info about this on the front page. Read it.
  21. GROUP BY must often be applied to aggregate functions to get a correct result. The reason for this is because you need to determine what to aggregate on. Let's say we need to count the total goals of football players. Without a group by clause, we'd just count the goals in total. (I actually ran queries this time) With some example data: Player: ( player_id, name) 10, "Alessandro Del Piero" 14, "Mirko Vucinic" 3, "Giorgio Chiellini" player_goal: (match_id, player_id, goal_time) 1, 10, 34 1, 10, 56 1, 14, 90 4, 10, 13 4, 3, 89 Consider this query: (Counting total of goals) SELECT COUNT( * ) AS total, player_id FROM player_goal That query would return 5, 10. The reason for this is that the count is not based on (grouped by) a single player. We therefor get the total number of goals. We also get player_id 10 because it's the first value found. (5 goals by player_id 10) This query however, will count per player: SELECT COUNT(*) as total, player_id FROM goals GROUP BY player_id ORDER BY total DESC Here we will get three rows of result, looking like this. 3, 10 (3 goals for player_id 10) 1, 14 (1 goal for player_id 14) 1, 3 (1 goal for player_id 3) As you can see here, we use ORDER BY to sort on columns. In the above example, I order by total goals descending because it makes sense regarding the result we want. Ordering does not affect the result, only the ordering of it. We could also sort on a second column. This would make more sense if an INNER JOIN to the player table is done. We could then sort goal scorers according to name as an example: Count goals per player, then order by total goals, then player name SELECT name, COUNT(*) AS total FROM goal INNER JOIN player ON ( goal.player_id = player.player_id ) GROUP BY goal.player_id ORDER BY total DESC, name ASC LIMIT 0 , 100 This would return this result: Alessandro Del Piero, 3 (3 goals, player_id 10) Giorgio Chiellini, 1 (1 goals, player_id 3) Mirko Vucinic, 1 (1 goals, player_id 14) I have personally tested and confirmed this on a very similar dataset.
  22. Sorry for misinforming you. Good example of source credibility here. When a forum user like me tells you one thing and Stack Overflow and Larry another, listen to the big guns. Always be critical. The examples and how INNER/OUTER joins work should be correct, though. Inner join and Join is also identical. Sorry again. I thought I knew this stuff good enough to not confirm my answer by other souces. Clearly not.
  23. Inner joins are exclusive. Outer joins are inclusive. That's the most important. A join and Inner Join is the same. Here's an example on OUTER JOIN: Users: (user_id, username) 1, Antonio Conte 2, Dimitri Vorontzov Posts: (post_id, user_id, content) 5345, 2, "Thank you, HartleySan....." 5453, 1, "Inner joins are exlusive...." 5335, 10, "Love this forum With Inner joins/joins, the post with ID 5335 won't be included (exlusive - because user_id 10 does not exist). With Outer joins, post 5445 will be included with null as user_id and username. (inclusive) Edit: Corrected misinformation.
  24. Using an IDE? Could be from there. If you are, right click project, select "properties" (or similar) and find charset there. My IDE has used macRoman too many times... It could also be an mysql thing. Try mysql(i)::set_charset(). This is also a common problem. http://php.net/manual/en/mysqli.set-charset.php
×
×
  • Create New...