Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I shall explain step by step how to get this working.</p> <p>Step 1 - Create an Yii web app</p> <p>Navigate to your Yii framework path in your console and create a new webapp. In my case I used this in my console:</p> <pre><code>cd c:\zeus\yii-1.1.10.r3566\framework yiic webapp c:\zeus\www\yiiblog </code></pre> <p>where c:\zeus\yii-1.1.10.r3566\framework is my path to Yii php framework and c:\zeus\www\yiiblog is the path to my Yii webapp test folder</p> <p>Stept 2 - fake my domain to dev.yiiblog.com</p> <p>Go to C:\Windows\System32\drivers\etc and edit your hosts file by adding this line:</p> <pre><code>127.0.0.1 dev.yiiblog.com </code></pre> <p>Step 3 - alter apache httpd.conf file</p> <pre><code>&lt;VirtualHost *:80&gt; DocumentRoot "c:/zeus/www/yiiblog" ServerName dev.yiiblog.com ErrorLog "logs/dev.yiiblog.com-error.log" CustomLog "logs/dev.yiiblog.com-access.log" common &lt;/VirtualHost&gt; </code></pre> <p>and restart apache service. I used in my windows console:</p> <pre><code>net stop apache net start apache </code></pre> <p>where my Apache 2 service is named "apache" not "apache2.2" like the default one.</p> <p>Step 4 - create a database and configure a database connection into Yii</p> <p>I've created a database yiitest and a user yiitest. Then I opened my Yii configuration file located ad /protected/config/main.php and edited the connection to MySQL:</p> <pre><code>'db'=&gt;array( 'connectionString' =&gt; 'mysql:host=localhost;dbname=yiitest', 'emulatePrepare' =&gt; true, 'username' =&gt; 'yiitest', 'password' =&gt; 'password', 'charset' =&gt; 'utf8', ), </code></pre> <p>Step 5 - download dburlmanager Yii extension</p> <p>Go to Yii dburlmanager, download the Yii dburlmanager extension <a href="http://www.yiiframework.com/extension/dburlmanager/" rel="nofollow noreferrer">http://www.yiiframework.com/extension/dburlmanager/</a> and extract it to your /protected/extensions folder</p> <p>Step 6 - Create MySQL database tables and add dummy data</p> <pre><code>CREATE TABLE IF NOT EXISTS `articles` ( `seoURL` varchar(100) NOT NULL ) ENGINE=InnoDB; INSERT INTO `articles` (`seoURL`) VALUES ('first-post'), ('another-post'), ('post/value'), ('website/page1'); CREATE TABLE IF NOT EXISTS `pages` ( `seoURL` varchar(100) NOT NULL ) ENGINE=InnoDB; INSERT INTO `pages` (`seoURL`) VALUES ('page-first-post'), ('page-another-post'), ('page/post/value.html'), ('page-website/page1'); </code></pre> <p>Step 7 - Create your Yii custom Controllers</p> <p>Create under /protected/controllers folder two php files named ArticleController.php and PageController.php:</p> <p>ArticleController.php content:</p> <pre><code>&lt;?php /** * @filename ArticleController.php */ class ArticleController extends CController { public function actionView() { $this-&gt;render('view', array( 'article' =&gt; isset($_GET['article'])?$_GET['article']:'', )); } } </code></pre> <p>PageController.php content:</p> <pre><code>&lt;?php /** * @filename PageController.php */ class PageController extends CController { public function actionView() { $this-&gt;render('view', array( 'page' =&gt; isset($_GET['page'])?$_GET['page']:'', )); } } </code></pre> <p>Step 8 - create your custom Yii views</p> <p>Create your view files corresponding to those controllers above with the path /protected/views/article/view.php and /protected/views/page/view.php:</p> <p>Article view content:</p> <pre><code>&lt;h1&gt;Article View Test&lt;/h1&gt; &lt;br /&gt; &lt;?php if (isset ($article)) echo "article: $article"; ?&gt; </code></pre> <p>Page view content:</p> <pre><code>&lt;h1&gt;Page View Test&lt;/h1&gt; &lt;br /&gt; &lt;?php if (isset ($page)) echo "page: $page"; ?&gt; </code></pre> <p>Step 9 - add custom Yii url rules</p> <p>Open again your main.php Yii config file and set your urlManager to something similar to:</p> <pre><code>'urlManager'=&gt;array( 'urlFormat'=&gt;'path', 'class'=&gt;'ext.DbUrlManager.EDbUrlManager', 'connectionID'=&gt;'db', 'rules'=&gt;array( '&lt;article:[\w\/.-]+&gt;'=&gt;array( 'article/view', 'type'=&gt;'db', 'fields'=&gt;array( 'article'=&gt;array( 'table'=&gt;'articles', 'field'=&gt;'seoURL' ), ), ), '&lt;page:[\w\/.-]+&gt;'=&gt;array( 'page/view', 'type'=&gt;'db', 'fields'=&gt;array( 'page'=&gt;array( 'table'=&gt;'pages', 'field'=&gt;'seoURL' ), ), ), '&lt;controller:\w+&gt;/&lt;id:\d+&gt;' =&gt; '&lt;controller&gt;/view', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;/&lt;id:\d+&gt;' =&gt; '&lt;controller&gt;/&lt;action&gt;', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;' =&gt; '&lt;controller&gt;/&lt;action&gt;', ), 'showScriptName'=&gt;false, ), </code></pre> <p>Step 10 - create .htaccess file</p> <p>Create a .htaccess file under your web app root and etid its content to:</p> <pre><code>Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php </code></pre> <p>Step 11 - test your SEO Friendly URLs</p> <pre><code>dev.yiiblog.com/first-post dev.yiiblog.com/page-first-post </code></pre> <p>etc</p> <p>Have fun creating awesome blogs or other web apps with complete url managing power.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload