generating a html image elements in cakephp - php

When I browse "localhost/ProjectName/users" then I get a user account image like
But When I browse "localhost/ProjectName/users/add" then I get a user account image like
But I wanna see correct image all actions.
My code is below.
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="img/penguen.jpg" class="user-image">
<?php $this->User = ClassRegistry::init('User');?>
<span class="hidden-xs">
<?php if (AuthComponent::user('id')): ?>
<?= AuthComponent::user('username') ?>
<?php endif; ?>
</span>
</a>

<img src="img/penguen.jpg" class="user-image">
was your mistake.
Leverage the helper to generate "valid" links for you, problem solved:
$this->Html->image('penguen.jpg', ['class' => 'user-image']);
Never use manual a or img tags with manually built URLs, that can only go wrong.

Related

How to link to a specific part of a page HTML PHP

I am trying to link to a specific part in my php page. I have tried all the other answers on here but none of them have helped my special problem. This is how I am trying to go to the link
<a href="<?php echo $userLoggedIn; ?>#posts_tab">
So when the user clicks the dropdown they see a list of things. One of those things being the word Profile and when the user clicks on their profile they go to their own personal profile. When they are there they have a list of items at the top that look like this:
So what I want to do is when they click the profile they are automatically on the Profile Posts tab. Like a default option. For some reason it's not working for me and I can't figure out why. Any help please ?
header.php:
<a href="<?php echo $userLoggedIn; ?>#posts_tab">
</a>
profile.php:
<a style="color: #000;" id="posts_tab" href="javascript:void(0)" onclick="openCity(event, 'Posts');">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding">
<center>Profile Posts</center>
</div>
</a>
I believe this is what you want, you need to let your profile page know that you want to load that part of profile.php, you can do it different ways I have used php and GET as example, I've sent a parameter on the URL and received it on profile.php
header.php
<a href="<?php echo $userLoggedIn; ?>?tab=posts_tab">
profile.php
<?php
$tab = $_GET["tab"];
if ($tab == "posts_tab"){
?><script>openCity(event, 'Posts');</script><?php
}
?>
<a style="color: #000;" id="posts_tab" href="javascript:void(0)" onclick="openCity(event, 'Posts');">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding">
<center>Profile Posts</center>
</div>
</a>

Anchor Tag automatically calling href Without Click in Codeiginitor

Here in My View:
<div class="dropdown">
<button class="btn dropdown-toggle" type="button" data- toggle="dropdown">Dropdown Example
<span class="caret"></span></button>
<ul class="dropdown-menu">
<?php
foreach($site as $sites)
{
echo '<li >"'.$sites->site_title.'" </li>';
}
?>
</ul>
</div>
<?php
}
?>
i want to redirect when user click on $sites->site_title
but how it working is it automatically redirects to url
enter code here"<li><a href='shop/viewSiteId?id=".$sites->site_id."'>".$sites->site_title."</a></li>";
and get that id by using GET method
A redirect is the programmatic way to send a browser to a URL. In other words, a call to redirect is like clicking a link. They are not intended to work together in the way you have tried.
<?php
foreach($site as $sites) : ?>
<li>
<a href='<?= base_url("shop/viewSiteId?={$sites->site_id}"); ?>'><?=$sites->site_title; ?></a>
</li>
<?php endforeach;
If you are not familiar with the syntax, know that <?= is the shortcut way to write <?php echo
I've also used PHP Alternative Syntax for Control Structures and dropped in and out of the PHP processor a bunch of times. For me, that is the easier way to read and write this kind of thing. (Your mileage may vary.)

Doesn't display php echo values from mysql

I have 2 tables:
TABLE users (id, name, image, user_group_id)
TABLE user_groups (id, name, menu)
column menu value contains something like this:
<img src="../images/employees/'.$row_UserDetails['Image'].'" alt="">
Now at img src its creating a problem.
'.$row_UserDetails['Image'].'
This doesn't display the value.
Why is that and how do we fix this?
I want to display results from recordset UserGroup like this:
Now the value coming from php mysql is: <img src="../images/employees/'.$row_UserDetails['Image'].'" alt="">
you see .$row_UserDetails['Image'].
This value must be abc.jpg which comes from Recordest UserDetails:
On this php page if i want to display user name, i use php echo like this: <?php echo $row_UserDetails['Name'];?>
When using echo in php you will need to escape the quotes as they cause problems.
<header id=\"header-navbar\" class=\"content-mini content-mini-full\"> <ul class=\"nav-header pull-right\"> <li> <div class=\"btn-group\"> <button class=\"btn btn-default btn-image dropdown-toggle\" data-toggle=\"dropdown\" type=\"button\"> <img src=\"../images/employees/\"" .$row_UserDetails['Image']. "\" alt=\"\"> <span class=\"caret\"></span> </button> <ul class=\"dropdown-menu dropdown-menu-right\"> <li> <a tabindex=\"-1\" href=\"my-profile.php\"> <i class=\"si si-user pull-right\"></i> My Profile </a> </li> <li> <a tabindex=\"-1\" href=\"../logout.php\"> <i class=\"si si-logout pull-right\"></i>Log out </a> </li> </ul> </div> </li> </ul>
</header>
You say you echo $row_UserDetails['Image'], but I don't see an echo statement anywhere. Also, if that PHP code is really in your database like that, I believe you are on the wrong track.
Much better would be to use some sort of placeholder, and replace that by your desired database value when rendering that menu.
Something like this:
// assume something like "... <img src="../images/employees/%{image}"> ..."
// in the menu column, where '%{image}' serves as a placeholder
echo str_replace('%{image}', $row['image'], $row['menu']);
You need to echo your tag or echo your data inside the src attribute to use the value return by $row_UserDetails['Image'].
If you have done so, this may be the problem.
You have a issue with cocatenation. Your code should be like this
<?php echo "<img src='../images/employees/".$row_UserDetails['Image']."' alt='test'/>"; ?>
This article mat help you : https://teamtreehouse.com/community/why-do-we-use-concatenation-when-outputting-this-img-tag-with-php
Best regards !

PHP wordpress if a text value is empty, echo

I'm building a wordpress theme. In the backend, the user has the option to enter the url for their social networks (i.e. twitter, facebook, instagram etc). These URL's are then dynamically added to images in the theme front end linking to the respective networks.
The issue I have is that if a user doesn't enter a url for a network, I don't want the image to display. I am trying to write code that says, if the url is blank, echo 'class="hidden"' - this class has display:none in the css.
here is a snippet of my php:
<ul class="icons">
<li <?php if (get_theme_mod('footer_twitter')==0) {echo 'class="hidden"'; } ?>><span class="label">Twitter</span></li>
</ul>
and the css:
ul.icons li.hidden {
display:none;
}
The php code above currently outputs the echo statement for all cases, even when a url is entered in the backend. Can anyone help me with this code
Check the return of "get_theme_mod()" You can check this by using, cause i dont think it "== 0". http://codex.wordpress.org/Function_Reference/get_theme_mod
var_dump(get_theme_mod('footer_twitter'));
//string(0)
Here is your new code:
<ul class="icons">
<li class="<?php echo empty(get_theme_mod('footer_twitter')) ? 'hidden' : ''; ?>">
<a href="<?php echo get_theme_mod('footer_twitter'); ?> " class="icon circle fa-twitter">
<span class="label">Twitter</span>
</a>
</li>
</ul>
Please check this Syntax: http://php.net/manual/en/control-structures.alternative-syntax.php its the best way to code control structures in your "View" code.
<?php if (!empty (get_theme_mod( 'set_address2' ))) {
echo get_theme_mod( 'set_address2');
}?>
This seemed to work for me in Wordpress.
Let me know if this works.

Easiest way for user to update slider and gallery images using Concrete5?

To create an editable pane in C5 I use the following between div tags so the user can simply use the content editor to add text. This works quite well:
<div class="myWrapper">
<?php
$a = new Area('WelcomeText');
$a->display($c);
?>
</div>
But what do I do when the mark-up is a little complicated? I would like to get user to update the 2 images and respective links themselves. Eg picture: http://i48.tinypic.com/4jma8p.png
What is the easiest way for non-code literate users to do this?
<ul class="Gal_2">
<li class="Frst">
<a href="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG2.jpg" rel="group">
<img src="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG2.jpg" width="224" height="150" alt="Island Rab" align="left" />
</a>
</li>
<li>
<a href="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG1.jpg" rel="group">
<img src="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG1.jpg" width="224" height="150" alt="Island Rab - Lopar beach" align="right" />
</a>
</li>
</ul>
Thanks in advance...
PC
Create a custom block with the free Designer Content addon: http://www.concrete5.org/marketplace/addons/designer-content
The block you create will have two image fields that link to other pages, and then use "static html" fields to surround the images with your <ul> and <li> tags.
This is actually a perfect use case for Designer Content, so it should be fairly self-explanatory. But if you run into problems, post a message to the support forum (or just email me directly at concrete#jordanlev.com).

Categories