Jump to content
Larry Ullman's Book Forums

KeepLearning

Members
  • Content Count

    54
  • Joined

  • Last visited

Everything posted by KeepLearning

  1. Thanks. But following Larry's example, this works for me: 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 'site/page/<view:\w+>'=>'site/page', ] ] The following two URLs now return the correct page: ullman.local/index.php/site/page/testpage1 If there is no htaccess file, then set 'showScriptNam
  2. Thanks for clarifying that. Yes, I did try renaming the "page" folder to "pages", as noted in my previous post, but that did not solve the problem. Actually, I have now deleted the entire project, and re-created it, but still the problem remains. I have documented every step I have taken, as follows: Start in E:\xampp\htdocs and run these: composer self-update composer global update composer create-project --prefer-dist yiisoft/yii2-app-basic ullman Next, modify config/db.php to connect to the database, which I downloaded from the YiiBook2 website. Also, I've previously mod
  3. Thanks Brent, but it still doesn't work for me. My static page is now located here: E:\xampp\htdocs\ullman\views\site\page\testpage1.php My urlManager looks like this: 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 'page/<view:\w+>'=>'site/page', ] ] And
  4. Actually, I don't think anything has worked so far. Even when I thought something was working, I was actually seeing the home page, instead of the static "About" page. So I need to start over, using a new static page that is called "testpage1" instead of "About" -- as per Larry's suggestion. Here is the location of my new static page: E:\xampp\htdocs\ullman\views\site\page\view\testpage1.php It contains this code: <?php use yii\helpers\Html; /* @var $this yii\web\View */ $this->title = 'About'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-a
  5. Thanks Brent, but I could not get it to work. Here's my URL code, including your suggestion: 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 'page/<view:\w+>'=>'site/page', ] ] Even after adding your code, I still need to disable pretty urls to access this web pa
  6. Thanks, but I knew that already. The problem is that with this setting: 'enablePrettyUrl' => true, the code in the book does not work. Here is the code that is provided in the book: 'page' => ['class' => 'yii\web\ViewAction'] Is there some way to modify the code in the book to make it work even when pretty URLs are enabled? Thanks.
  7. In my config/web.php file, I have this: 'db' => require(__DIR__ . '/db.php'), 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => true, 'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ] ] If this is set to true: 'enablePrettyUrl' => true, then this url does not work: ullman.local/index.php/site/page/view/about However, if this is set to false: 'enablePrettyUrl' => false, then the same url d
  8. Hi Larry. I'd very much appreciate a reply from you about this. Should I expect your reply sometime this week perhaps? Thanks.
  9. I'm not sure how the second part of this example is related to the first, and where it belongs. I am quoting from page 174 of YiiBook2: # models/Page.php public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); } This means you can fetch every page with every page author in one step: $pages = Page::find()->with('user')->all(); I'm guessing that with('user') calls the getUser method. Is that right? But in which file does the second part of the example belong? In the view file?
  10. I've read through the example at the top of page 161 several times now, and I just cannot understand it. So I tried out the code, but I cannot get it to work. Here's what I did: I downloaded the yiibook2_cms.zip file. I installed it as ullman.local, and verified that it works in my browser (using Xampp on Win 7). To be clear, the composer.json file is here: E:\xampp\htdocs\ullman\composer.json. In Sublime Text, I opened SiteController.php, added this code, and saved the file: [ 'page' => ['class' => 'yii\web\ViewAction'] ] As a result, my actions method now looks like this:
  11. For pretty urls, something that puzzled me was where to put the .htaccess file, but I realized it goes in the web folder.
  12. When I tried to run the downloaded SQL commands in phpMyAdmin, various error messages appeared, stating that no author table exists. So I searched for all occurrences of the word "author" and replaced them with "user", except for this line: `type` enum('public','author','admin') NOT NULL, Is this correct? The file I downloaded is: yiibook2_cms.sql.zip Thanks.
  13. Larry, Do you have any more chapters of the Yii Book? I mean the second edition, revised for Yii 2. I've read -- and mostly understood -- up to page 190, which is the last revised page. If you have more revised chapters, I'd be interested in reading them. No doubt, other readers would too. Can you post any additional chapters on your website and let everyone know? Thanks.
  14. Larry, on page 150 of the YiiBook2 (latest version), you write that the following code is "verbose, redundant, and illogical": $model = new Page(); $model = $model->findOne($id); Instead of creating an instance of the Page class, as shown above, you say we should use a static class instance (or static method?), like this: if (($model = Page::findOne($id)) !== null) { return $model; etc. I don't understand why the first example is "verbose, redundant, and illogical", and why the second example is preferred. Can you please explain this? Thanks.
  15. Your answer this time really cleared up this question for me. Thanks. Actually, I'm amazed that you are so responsive. On the other hand, customer feedback can help any business improve their product. Your product is your book, and I suppose your reader feedback helps you polish your book. It's a great idea, if you have the time and motivation. By the way, I do appreciate the other answers you have provided -- even those that I did not thank you for specifically. I don't want to clutter the forum with posts that say "Thanks", but have no other value. Anyway, I do read and appreciate yo
  16. Larry, I think you are saying that in this code: "public function myFunctionName() { return array('accessControl'," the "accessControl" part tells Yii that this function is calling a filter (from page 142). The function could be named anything, such as "myFunctionName". It does not need to be named "filters()". The next part: ", 'httpsOnly + account',); }" tells Yii that httpsOnly must be applied to the account action. Is this correct? By the way, why is there a comma after 'account'?
  17. On second thought, I don't see how the filters() function is calling the filterHttpsOnly function, so now I am just plain confused.
  18. Larry, I think you are saying: The following code dictates that the httpsOnly filter should be applied to the "account" action: public function filters() { return array( 'accessControl', // account must be accessed over HTTPS: 'httpsOnly + account', ); } The above code calls the following function, which verifies there is a secure connection before running $fc: public function filterHttpsOnly($fc) { if (Yii::app()->getRequest()->getIsSecureConnection()) { $fc->run(); } else { throw new CHttpException(400, 'This page needs to be accessed securely.'); } } I guess
  19. Version 0.5 Page 167 Quote: "// Works safely: $model = Page::model()->find('id=:id', array(':id'=>$id));" Larry, What exactly does the colon do? What does the array do? I know they make the query safer, but how? Thanks.
  20. Version 0.5 page 157 Quote: "# protected/controllers/SiteController.php public function actions() { return array( 'page' => array('class' => 'CViewAction', 'defaultView' => 'about') ); } To change the layout used to encase the view, assign the alternative layout name to the layout attribute in that array." Larry, I understand the example, but not the last sentence. It doesn't seem to relate to the example. Can you please explain it in other words? Thanks.
  21. Larry, from what you have written, I understand that protected/views/user/create.php is being rendered by an instance of UserController. That instance of UserController is the current object. It is referred to by $this -- even within the view file. However, I do not know what general rule would tell me that the UserController instance is the current object. If while coding at some future time, I am not sure what the current object is, I suppose I could type "echo get_class($this);". Does that make sense?
  22. I think I understand, but to be sure: $this UserController" uses the term $this, whereas "$model User" does not. The distinction is that "$this User" might mean "the current user accessing the site", whereas "$model User" means the instance of $model that contains the currently selected user. Have I gotten it right yet? I get the impression this is only an informal documentation syntax, without clearly defined rules. Is this true?
  23. I think you are saying 1. "$this UserController" is a variable representing "the current instance of UserController" 2. "$model User" is a variable representing "the current user in the current model" Am I on the right track? Thanks.
  24. version 0.5 Page 154 - 155 Larry, 1. What exactly is is a filter chain? 2. In the particular example given, does "invoking its run() method" mean invoking the "account" action's run method? 3. Where can I find the "account" action? Is it in the yii_cms? Should I search for "actionAccount" as a string within the files in the Protected folder? 4. If the "Account" action is hypothetical, would it really have a method called "run()"? If not, what is a run() method? Quoting from the book" "The method needs to take one parameter, which will be a filter chain. This
×
×
  • Create New...