friendly urls with yii history.js - yii

currently when using history.js in my view my url looks like this
http://localhost/dev/clubs/
when i sort OR go to the next page it adds the modulesName, Clubs and relationTable to the url
http://localhost/dev/modulesName/clubs/index/?Clubs_sort=relationTable.Make.desc&page=2
how would i make it look nicer? Say something like this maybe (without the /index/ too)
http://localhost/dev/clubs/?sort=Make.desc&page=2
currently in my modules controller i have this
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Clubs', array(
'criteria' => array(
'with' =>'Make',
),
'sort'=>array(
'defaultOrder'=>'Make.Make ASC',
'attributes'=>array(
'Make.Make'=>array(
'asc'=>'Make.Make',
'desc'=>'Make.Make DESC',
)
)
),
//for friendly url when history,js is enabled
'pagination'=>array(
'pageVar'=>'page'
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
and in my url manager i have this
'<action:(clubs|finance)>' => 'modulesName/<action>',
any idea how to fix this? Thanks

You can use the url manager to do this in config
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'mypagename' => 'modulename/controllername/actionname'
//any number of url's can be changed from here and no js is needed
)
),
Here I can give any name as my page name and as many as url's I like

Related

Yii Slugs using url manager

So using yii I want to have urls like this:
mydomain.com/some-short-slug
And this url to map the following:
mydomain.com/book?bookslug=some-short-slug
How can I do this?
You need do this inside url-manager:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
'rules' => array(
...
'<slug>'=>'book/index'
...
),
Now, if url like mydomain.com/some-short-slug, you have $slug equal to "some-short-slug" in the actionIndex of BookController

How to Configure yiibooster

thanks for reading, i am wondering how to install
YiiBooster
, do i need to install
YiiBootstrap
first ?
I want to install it by hand , is it enough to extract it to extensions folder and than configure the main.php or is there something i am missing ?
Also how can i make this point to the right path
'booster' => array(
'class' => 'path.alias.to.booster.components.Booster',
),
You don't need to install bootstrap. Yiibooster includes all bootstrap files it needs. Just download Yiibooster, unpack to the extension folder and add the below to your main config file,
'booster' => array(
'class' => 'ext.yiibooster.components.Bootstrap',
'responsiveCss' => true,
),
Then add the following in the preload section of the config,
'booster',
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
// preloading 'log' component
'preload'=>array('log','bootstrap'),
// application components
'components'=>array(
//
'bootstrap' => array(
'class' => 'bootstrap.components.Booster',
'responsiveCss' => true,
),
Rename folder name yiibooster-4.0.1 to yiibooster
Step 1:
'preload' => array(
'booster',
),
Step 2:
'booster' => array(
'class' => 'ext.yiibooster.components.Booster',
'responsiveCss' => true,
),
Note: Booster this Class name
//Use view file
<?php
$this->widget('booster.widgets.TbExtendedGridView',
array(
'filter' => $model,
'fixedHeader' => true,
'type' => 'striped bordered',
'headerOffset' => 40,
// 40px is the height of the main navigation at bootstrap
'dataProvider' =>$model->search(),
'template' => "{items}",
'columns' => array(
'id',
'firstname',
'lastname',
'age',
'address',
'email',
),
)
);
?>

URL management using Yii

I have url: /profile/profileBase/index where "profile" is module, "profileBase" is controller and "index" is action.
I want to url manager would accept route like: /profile/read/index
where "read" could be alias of controller.
Is there any way to do this using url manager rules?
Thanks
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'profile/read/index '=>'profile/profileBase/index'
),
),
You should simply add the following rule in urlManager config :
'profile/read/index'=>'profile/profileBase/index',

Yii Parameterized Hostnames. what am I missing?

I am not able to get the yii parameterized hostnames working. I am trying to display http://member.testsite.com when the user clicks on login from http://www.testsite.com.
I have the member module created with SiteController.
In my rules, I have:
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'http://member.testsite.com' => 'member/site/index',
),
In my login, I have the URL pointing to
'url'=>array('member/site/index')
When I hover over login, it shows member.testsite.com, but when I click it takes me to website-unavailable.com
When I change the rules to
'http://member.testsite.com' => 'member/<controller>/<action>',
it takes me to testsite.com/member/site/index/
Am I missing any step?
Example:
'rules' => array(
'://<member:\w+>.<host>/<controller:\w+>/<action:\w+>'
=> '<controller>/<action>',
),

Yii CListView summary text

Is there any way to hide "Summary" for CListView without loosing pagination. By summary i mean text like "Displaying 1-2 of 2 result(s).". Or maybe I should use different widget?
Try the following to get more control over the look of your CListView output:
'template'=>'{items} {pager}'
You can even use HTML in the template.
Ok, I didn't get it at first, when looking into CListView code, but setting 'summaryText' to '' will do the work. I've realised that second time when I was staring at $summaryText === null
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'summaryText'=>'',
'itemView'=>'_indexview',
));
Here is the example for CListView:
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view',
'ajaxUpdate' => false,
'emptyText' => 'No records found.',
'summaryText' => "{start} - {end} из {count}",
'template' => '{summary} {sorter} {items} {pager}',
'sorterHeader' => 'Sort by:',
'sortableAttributes' => array('title', 'price'),
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
'cssFile' => '/css/pager.css',
'htmlOptions' => array('class' => 'pager'),
'maxButtonCount' => '10',
'prevPageLabel'=>'←',
'nextPageLabel'=>'→',
'header'=>'Pages: ',
),
));
You should try this:
'summaryText' => FALSE,
You may hide it by adding CSS in the page like below.
<style>
.summary{
display:none;
}
</style>
Here is my suggestion
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $best_seller_data,
'itemView' => 'alsoBestseller',
'summaryText'=>false,
));