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

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')); ?>

Related

Dropdownlist with Add and Remove function

I am using the code below display multiple selected values for users to choose from.
<div class="row">
<?php echo $form->labelEx($model,'site_staff'); ?>
<?php //echo $form->textField($model,'site_staff',array('size'=>60,'maxlength'=>255)); ?>
<?php //echo $form->dropDownList($model,'site_staff', CHtml::listData(Biodata::model()->findAll(), 'full_name', 'full_name'), array('empty'=>'Select')); ?>
<?php echo $form->dropDownList($model,'site_staff',CHtml::listData(Biodata::model()->findAll(),'full_name','full_name'),array('multiple'=>'true','prompt'=>'select ','selected'=>'selected'));?>
<?php echo $form->error($model,'site_staff'); ?>
</div>
I am trying to achieve the following but have no idea how to go about:
1) Add and remove function
- When a user choose one or more, by clicking "Add", will display the selected value in another dropdown list
- User can also remove any selected data in the latter dropdown list
So far, the single dropdown works well but users need to use CTRL-CLICK to select more than one option which is not a feasible way of selecting.
Any help is greatly appreciated.
Hii you can also use a multiselect dropdown for this.
Use yii select2 for this.
this is nice extension Please read more about this from here
http://www.yiiframework.com/extension/select2/

SocialEngine 4 - Followers/Following status display too long

I have problem at columns Followers/Following which I put on the right side of my website and also on browse members page. The problems are:
1) when user post too long status its not displayed right on firefox
2) in cause of the long text follow/unfollow are displayed someone in the middle of the status
You can see what I mean by the added images.
What I suggest for a fix (but I don't know how to do it :() is this:
just remove status in this boxes (its not really needed to see last user status there)
or
limit the status characters
Also is there a way users can "clear" their status because I think it stays there until new one is posted, which is pretty stupid. Like if you post something which is ralated to something now but makes non sense in the futre and then you dont post new status for like 10 days and someone sees it, it will look stupid.
thats the code
<div class='profile_friends_body'>
<div class='profile_friends_status'>
<span>
<?php echo $this->htmlLink($member->getHref(), $member->getTitle()) ?>
</span>
<?php echo $member->status; ?>
</div>
Thanks in advance and I think fix like that will be helpful to others too.
image2
I managed to remove it from application/modeules/User/widgets/profile-friends-followers/index.tp
also its the same in profile-friends-followers and profile-friends
in the files I found this
<div class='profile_friends_body'>
<div class='profile_friends_status'>
<span>
<?php echo $this->htmlLink($member->getHref(), $member->getTitle()) ?>
</span>
<?php echo $member->status; ?>
</div>
and when you remove status; ?> then statuses are not shown anymore on this widgets, but I wanted just to limit the displayed characters and tried to use substr but couldn't manage to do it at the first time

buddypress get activity title

i am trying to get activity title for each activity by using the following code. but it is repeating the activity title for each activity .
<h2 class="posttitle">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php _e( 'Permanent Link to', 'buddypress' ); ?>
<?php the_title_attribute(); ?>"><?php the_title(); ?>
</a></h2>
i Also tried using calling bp_get_activities_title() but it gives no result can some one help me out with this
i believe that is because the_title() just prints out the title. try using the following in order to get the title.
<?php echo get_the_title(bp-activity->$ID); ?>
Sorry for late answer, but how and/or why would activities have a title? You could possibly get the text of the activity itself and use this as the "title" with
echo $activities_template->activity->content;
Perhaps there is another variable in there you might find useful. I suggest printing the array
print_r($activities_template->activity);
and see what's in it.
EDIT: Though you better pray there is no HTML in ->content (or you can just strip the html out :] )

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.

Drupal - Print content in node template if tagged with certain taxonomy term?

I want some content to only be printed in my node-type.tpl.php if the node has a certain taxonomy term.
With the following I can print the term's name if its ID is 5:
<?php print $node->taxonomy[5]->name ?>
Can I modify the code so it only prints something if the term ID is 5? I tried the following but it doesn't work:
<?php if ($node->taxonomy == '5'): ?>
Print something here if the term ID is 5.
<?php endif; ?>
Im a bit of a newbie with advanced theming so I was hoping to not have to mess about with my template.php.
It seems more complicated than necessary but could the code from here be altered:
Drupal - display blocks according to node's taxonomy term ID
Thanks
Got it working:
<?php if ($node->taxonomy[5]): ?>
print stuff here
<?php endif; ?>