Yii - urlmanager and active highlighting menus - yii

I've just figured out how to configure the urlmanager rules to work with rules such as
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<type:\w+>s'=>'article/index',
)
however, now my CMenu does not have active highlighting for my main menu with link
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'Articles', 'url'=>array('/articles')),
)); ?>
Can this active highlighting still work even though I want my URLs to look like '/articles'?

I've found a solution, seems kinda gross though. All I did was add an 'active' criteria to check if the current URI has '/article' as the front.
array('label'=>'Articles',
'url'=>array('/articles'),
'active'=>strpos(Yii::app()->request->requestUri, '/article')===0),

array('label'=>'Articles',
'url'=>array('/articles'),
'active'=>Yii::app()->controller->name == 'articles'),

Related

How to get url without pagination YII

this code takes url from page and display it
http://site<?= \Yii::$app->request->getUrl() ?>
But he takes it with pagination, like that:
site/category/page?p=2.
i need to take this url, but without pagination, only url, like that:
site/category/page
help me please. I think to use suffix, but idk hot it works if url didn`t have pagination
Add the below code to your UrlManager inside config/main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),

Yii CGridView hide filter input only

When using CGridView, the filter input fields are automatically generated by the component.
I want to select which columns will show the input field. For example:
My model has 5 columns. I want CGridView to show the input filter ONLY for columns 1 and 2.
Is there a way to do it without using CSS or jQuery, just adding some code on the CGridView options?
array(
'name'=>'col3',
'value'=>'$data->col3',
'filter'=>false,
)
should work.
If you want to remove all filters form the entire CGridView, configure 'filterPosition'=>''
Only comments and filter disappears...
example:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'usuario-grid',
'dataProvider'=>$model->search(),
//'filter'=>'false',
'columns'=>array(
'rut_usuario',
....
Setting 'filter'=>false, is working for me.
You can put 'filter'=> false, but this attribute will minimize the witdh of the column.. another way to disable the filtering on a specific column is to return a input with attribute 'disabled' like:
'filter'=>'<input type="text" class="form-control" name="UsersSearch[password]"
disabled>',

Move Buddypress Registration to index page

I have a custom index page. I need to have the buddypress registration on the index page. Something like facebook.
Can anyone help?
Thanks
You can simply copy paste the content of theme bp-default/registration/register.php into your page. You can copy everything that is there on register.php between these 2 lines:
<?php do_action( 'bp_before_register_page' ); ?>
and
<?php do_action( 'bp_after_register_page' ); ?>
But, but...
you need to remove this if clause
<?php if ( 'request-details' == bp_get_current_signup_step() ) : ?>
just remove the opening and closing if statement. Everything inbetween should stay as it is. But there's one problem, since you remove this if statement your registration form will always be visible. If you can't live with that then you need to do some workaround to fix this.

Special characters in Yii framework menu

I'm developing a CMS using Yii Framework. In developing the theme I have a problem. In the menus I have some special characters (The website is in Italian). the HTML markups for special characters doesn't work for menu items. And if I put the character itself it looks different. Here is my code:
<div class="horizontal-menu">
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'LE ATTIVITÀ', 'url'=>array('/site/page', 'view'=>'attivita')),
array('label'=>'NEWS', 'url'=>array('/site/page', 'view'=>'news')),
),
)); ?>
LE ATTIVITÀ is the one making the problem. How can I show special characters here?
CMenu's labels are HTML-encoded by default, so you should use array('label'=>'LE ATTIVITÀ', 'url'=>array('/site/page', 'view'=>'attivita')),.
However if you must use HTML-encoded strings in your code, you can turn the encoding off by setting the encodeLabel to false, like this $this->widget('zii.widgets.CMenu',array(
'items'=>array(),
'encodeLabel'=>false,
),

CHtml::link - how to add a html class?

On docs we can read:
public static string link(string $text, mixed $url='#', array $htmlOptions=array ( ))
Question:
I don't understand what $htmlOptions means here. I don't understand how to pass from this representation to a real code.
Can anyone please provide an example about how can we generate a link with a class defined.
Something like:
link hello
It's easier than you might think, although Yii's documentation is perhaps a bit more convoluted than needs to be. However, it does say that $htmlOptions is
additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see clientChange and tag for
more details.)
In essence, whatever key/value pairs you put into the array will come out as HTML attributes¹. So, what you want to do is
CHtml::link('link hello', '#', array('class' => 'hello'));
¹except the "special" values that the docs refer to, which will not end up rendered in HTML as-is but either modify the way link works slightly, or end up affecting the HTML in other ways.
<?php echo CHtml::link('Link Text',array('controller/action','param1'=>'value1'), array('target'=>'_blank','class'=>'hello'); ?>
It will be shown as below.
<!--if you disabled url manager in "protected/config/main.php" the output will be -->
<a target="_blank" class="hello" href="index.php?r=controller/action&param1=value1">Link Text</a>
<!--if you enabled url manager in "protected/config/main.php" the output will be -->
<a target="_blank" class="hello" href="controller/action/param1/value1">Link Text</a>
To get a detailed description about CHtml in yii Check this link.
<?php echo CHtml::link("Label Text" , array("/controller_here/action_here") , array('class' => 'class_here')); ?>
or
<?php echo CHtml::link("Label Text" , Yii::app()->createUrl("/controller_here/action_here") , array('class' => 'class_here')); ?>