Jump to content
Larry Ullman's Book Forums

KeepLearning

Members
  • Posts

    54
  • Joined

  • Last visited

Everything posted by KeepLearning

  1. Okay Larry, I think I understand after all. But again, why is the syntax not $this->SiteController and $model->User ? I mean, why is the "->" omitted? Thanks.
  2. Interesting. I'll read up on that. Thanks.
  3. This has gotten too abstract for me. Some examples would really help. Thanks.
  4. I think you are saying that 1. "@" is just a documenting convention, and 2. "$this" is necessary to indicate a particular instance of SiteController But why is the syntax not $this->SiteController and $model->User ? I mean, why is the "->" omitted? Thanks.
  5. Version 0.5 Page 150 Larry, Can you please break this paragraph down or explain it another way? I've read it and re-read it numerous times. I understand the preceding and following pages, but not this paragraph and example. Thanks. "However, when you’ve identified a parameter in a rule that’s not part of the route, it will only be passed to an action if that action’s parameter is named the same. The earlier example code works, but this action definition with that same rule will throw an exception (Figure 7.1): # protected/controllers/PageController.php public function actionView($x) { // Etc."
  6. Why is "$this" necessary? There is only one SiteController.php. Why is the syntax not $this->SiteController and $model->User ? And why does "@" always precede "var"? Thanks. Reference: "The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object)." From http://php.net/manual/en/language.oop5.basic.php
  7. Antonio: I'm not familiar with your html syntax. I've always done it this way: <p><a href="#Arrive here">Click here</a></p> <p> </p> <p><a name="Arrive here">Arrive here</a></p> My way does not involve any id, which is why I did not understand the term "anchorid". I am puzzled that we are creating anchor points differently. What do you think? Thanks.
  8. Version 0.5 Loading a Single Model The following two examples work together. The second calls the first. I believe the purpose is to retrieve a record from a table. And I believe each occurrence of $id represents the primary key value of the particular record we want. My question is, how do these functions know which table to search in? page 136: public function loadModel($id) { $model = Page::model()->findByPk($id); if ($model===null) { throw new CHttpException(404, 'The requested page does not exist.'); } Page 139: public function actionView($id){ $this->render('view',array( 'model'=>$this->loadModel($id), )); }
  9. Antonio: Thanks for explaining what a record is. I knew already, but you provided a different perspective. What actually confused me was "post" and "post record". I did not realize that Larry was referring to a hypothetical project containing a table called "post". I thought he was discussing the yii_cms project. Thanks for clarifying. Yes, OOP seems like a different language at times -- not procedural php! It's taking patience. I do appreciate your help.
  10. Well, maybe this Yii book will eventually illuminate the benefits OOP for me, as it shows OOP in action.
  11. Larry, I understand your conundrum. You can't hope to please everyone. Yet the clearer your writing, the more readers you will reach, without alienating any of them. As for myself, while I am not an OOP programmer, I nonetheless do believe I am in your target market. After all, I have been able to understand most of your Yii book so far. Yet some passages in your book have indeed confused me. Hence, before you assume that confusion over simple points is an indication that the reader's background is inadequate, you should consider whether your presentation of the topic was sufficiently clear. You have very cleverly chosen to test-market your book while you write it. The added bonus is that the feedback you get is allowing you to crowd-source some of the editing, at your discretion. If this allows you to you make your book more readable by rephrasing a sentence, or adding a few words, or providing an example, how can your pro readers complain? They can simply skip the easy parts, and move on to whatever topics interest them.
  12. In the yii_cms database, there is no table called "Post". I do appreciate your help, Antonio, but actually, over the years, I have done some sophisticated ecommerce programming in php -- all written procedurally, from scratch. And I have read enough about OOP to have passing familiarity with it. If a person with my experience cannot readily understand certain passages in this book, then those passages should be clarified. It is to Larry Ullman's advantage to clarify any passages that puzzle readers. A book that is written clearly enough to be understood by average programmers will have a much larger market. On the other hand, if the book is actually intended only for sophisticated programmers such as yourself, then the marketing materials should clearly indicate that, in fairness to all potential buyers. I bought this book because I had the impression it would be suitable for a person with my background, and in fact, I have been able to understand most of it. I also understood there was a forum for seeking assistance. This latter point is especially important, because I have bought too many programming books in the past that started clearly enough, but then abandoned the reader by racing ahead with the more complex topics. As a teacher with many years experience, I have come to believe that sometimes apparently silly questions can prove to be very useful and illuminating. And as an educational author myself -- not programming-related -- I understand how easy it is to assume the reader already knows what I know. Hence, I make a special effort to never leave readers hanging, puzzled and frustrated. I do hope my many questions are welcomed in this forum, even if they reveal my ignorance. Sincere, accurate answers will help not only me, but no doubt other readers as well, who may be more reluctant to embarrass themselves by asking the kind of questions that I do. And I hope my questions will help Larry understand where improvements can be made, and that he considers the effort worthwhile.
  13. version 0.5 Page 129 As I read this book, I keep scratching my head, wondering what's so good about OOP (Object Oriented Programming). The clips example is a case in point. Why write 5 lines of code when you can write just 2, like this? $stockQuote = 'AAPL: $533.25'; echo $stockQuote; I can modularize my procedural code by using includes. So how can all the fuss and bother of OOP be worthwhile? I've read plenty of rationales defending OOP, written by people who studied it in college, but it seems more like a religion to me. Sorry, I don't mean to offend anyone. I've read some books on OOP php, and I'm patiently reading through this one, only because I want to take advantage of the code that's automatically generated and tailored to whatever tables I need. But frankly, I will probably write most custom code, queries etc, as procedural php.
  14. version 0.5 Page 129 Larry, I like your clear explanation of how column1.php is used. But if instead I wanted to use column2.php in a particular situation, where would I specify that? Can you please provide an example? Thanks.
  15. Thanks for the answer Larry. And how about question 2? Here's the sentence I'm confused about again. An example would be really helpful. Thanks. p 115. "{TIP} Because the page title is set by assigning a value to the controller instance, it can also be set within the controller action, if you’d rather."
  16. Version 0.5 Page 126 Quoting from the book: "For example, when updating a post record, the URL is something like http://www.example.com/index.php/post/update/id/23." Where is the file called "post"? I have searched the entire project, using Windows Explorer, and I cannot find it. Also, I've never heard of a "post record". What is that? Thanks.
  17. Version 0.5 Page 125 Larry, please provide and example to show us how this would work: "{TIP} Most of the time you use renderPartial() within one view file, you’ll want to pass along the variables it received to the other view file." Thanks.
  18. Version 0.5 page 120 Quoting from the book: "{TIP} To link to an anchor point on a page, pass ’#’ => ’anchorId’ as a parameter." What is "anchorId" ? An example would be helpful here. Thanks.
  19. Version 0.5 Two questions about page 115. 1. Quoting from the book: "<?php $this->pageTitle = Yii::app()->name . '::' . $model->title; ?>" Why are there two colons before $model->title ? I assume they will appear literally, but maybe they function as code -- I'm not sure. 2. Quoting from the book again: "{TIP} Because the page title is set by assigning a value to the controller instance, it can also be set within the controller action, if you’d rather." This sentence is saying 2 things, neither of which I understand. Larry, can you please break this down and provide an example? Thanks.
  20. version 0.5 Page 113 Quoting from the book: "The view files generated by Gii have comments at the top of them that indicate the variables that were passed to the view file. For protected/views/site/index.php, that’s: <?php /* @var $this SiteController */ For protected/views/user/create.php, you’ll see: <?php /* @var $this UserController */ /* @var $model User */ " My question: What actual variables are passed? Is SiteController a variable? Is UserController a variable? What exactly does "$model User" mean? Thanks.
  21. Okay, so this would be one example of that: protected/views/site/index.php
  22. Thanks for explaining that. I understand it better now. I guess this is the include code: <?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
  23. Version 0.5 Page 109 I can't find this file: protected/views/ControllerID/viewName.php Is this a general case address? If so, an example would help. Anyway, where exactly is this file? Thanks.
  24. Page 108, version 0.5 The following sentence seems to jump over several points, each of which needs a more detailed explanation. Consequently, I cannot understand this sentence at all: "the form used to both create and edit a record is its own file, and that file can be included by both create.php and update.php (those two files start by changing the headings above the form)." Larry, can you break this down please? Thanks.
  25. Here are some questions that crossed my mind while reading Chapter 5 (Version 0.5) Page 86 The book states, "If you also set a requiredValue attribute for the item in question, your error message can indicate what the required value is via {value}." My question: Larry, could you please provide an example showing how the value of {value} would be set? Page 91 Please show the code I would need to "create user-related scenarios for changing passwords". Also, in which circumstances would I set a scenario on an existing instance, as opposed to creating a new user? Page 93 Why is it necessary to write "filter" twice in this code: 'filter', 'filter'=>'strip_tags' ? Page 94 Wouldn't declaring search terms as safe be a security risk? Here is the code from the book: array('id, user_id, live, title, content, date_updated, date_published', 'safe', 'on'=>'search'), Page 95 Why would we need to compare passwords if the user is only just registering? How would he/she already know a password? Quoting from the book: // Password must match the comparison: array('pass', 'compare', 'compareAttribute'=>'passCompare', 'on'=>'register'), Page 95 I have read a credible article on the Internet stating that ENUM fields are "evil". If I prefer to avoid using an ENUM field, and instead use a separate table of "types" which lists these values 'public','author','admin' etc, and the table has a one to many relationship with User.type, how would I obtain the values from the types table for use in this rule? Here is the code from the book: array('type', 'in', 'range'=>array('public','author','admin')), Page 97 The book states: "Also, when you have a model that’s not based upon a database, you’ll need to add the attribute names and values to the attributeLabels() method yourself." How do these attribute labels end up being incorporated into various HTML forms? Page 101 Quoting from the book: $this->user_id = Yii::app()->user->id; My question: I understand the relationship, but aren't there many user.id values to choose from? How does the framework know which id is the correct one? Page 102 Here's a syntax question: 'date_entered' in the first example becomes $this->created in the second example. How can these refer to the same table field? Page 102 Can you please provide an example how I could "return false in the event handler method"? Quoting from the book: "As a final note on this concept, if the event that’s about to take place shouldn’t occur–for example, the model should not be saved for some reason, just return false in the event handler method." Thanks.
×
×
  • Create New...