Jump to content
Larry Ullman's Book Forums

KeepLearning

Members
  • Content Count

    54
  • Joined

  • Last visited

Community Reputation

0 Neutral

About KeepLearning

  • Rank
    Advanced Member
  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.
×
×
  • Create New...