I'm trying to do an if condiction in my HTML file in codeigniter that checks the URL and if it contains part of the URL it does one thing if doesnt it does something else
For example:
My URL is
localhost/index.php/cart/galery1
and when I click a photo it applies a filter with this URL
localhost/index.php/cart/galery1/2
the thing is that when I click in a photo after the filter it goes to something like
localhost/index.php/cart/galery1/2/2
There's a way I can do an if condiction checking the URL in my controler or my html ?
My code is something like that right now
HTML
<div id="top-industries" class="gallery">
<div class="container">
<h3 class="tittle">As Nossas Casas</h3>
<div class="gallery-bottom">
{foreach $products as $product}
<div class="view view-ninth">
<a href="galery1/{$product.cat_id}" class="b-link-stripe b-animate-go swipebox" title="Image Title"><img src="{$product.image}" alt="" class="img-responsive" width="330" height="219" target="_blank">
<div class="mask mask-1"></div>
<div class="mask mask-2"></div>
<div class="content">
<h2>CASA 1</h2>
<!--<p>A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart.</p>-->
</div></a>
</div>
{/foreach}
<div class="clearfix"> </div>
</div>
</div>
</div>
Controler
if($cat_id){
$data['catID'] = $cat_id;
$data['products'] = $this->Cart_model->get_casa($cat_id);
}
else{
$data['products'] = $this->Cart_model->get_products();
}
you have to set base_url(); here
application\config\config.php
$config['base_url'] = 'www.yoursite url.com';
and then use this base_url() in link like this
<a href="<?php echo base_url()?>galery1/{$product.cat_id}" class="b-link-stripe b-animate-go swipebox" title="Image Title"><img src="{$product.image}" alt="" class="img-responsive" width="330" height="219" target="_blank">
i think it will solve your problem
To get the segment from URL you should use CI's built-in library URI Class.
$this->uri->segment(n);
// your url - localhost/index.php/cart/galery1/2/3
$this->uri->segment(1); // returns conrtoller ie cart
$this->uri->segment(2); // returns function ie gallery1
$this->uri->segment(3); // returns 1st segment ie 2
$this->uri->segment(4); // returns 2nd segment ie 3
// you can also return default value when a uri segment is not available
$this->uri->segment(5, 0); // returns 0 because there is no 5th segment. Comes handy in condition -- will definitely help you here
// you can also use
uri_string(); // returns complete uri as a string ie cart/galery1/2/3
For more info read here.
Hope it helps you. :)
Create a new .tpl igual as the other one only changing what you want to change and then change the controller to
if($cat_id){
$data['catID'] = $cat_id;
$data['products'] = $this->Cart_model->get_casa($cat_id);
$this->smarty->view('fotos_galeria.tpl', $data);
}
else{
$data['products'] = $this->Cart_model->get_products();
$this->smarty->view('galeria.tpl', $data);
}
Related
I am using codeigniter framework in my web development and passing the value of image id using php code such below
<a href="<?php echo base_url('account/gallery/view'); ?>?id=<?php echo $imageDetail['imageId']; ?>">
<img src="" />
</a>
and getting the value at controller with this code $imageId = $this->input->get('id');
With the get method I used, it will display the url like this :
http://my-domain-name/account/gallery/view?id=1
But I want to display the url like this :
http://my-domain-name/account/gallery/1
So what I did is setting in the router with this code but it's not working.
$route['account/gallery/(:num)'] = 'default/Gallery_controller/view/$1';
My web still able to show the template of the web if I type http://my-domain-name/account/gallery/1 but display error in the field that I fetch from database because unable to get the imageId
use Regex instead of :num in route.php
$route['account/gallery/([0-9]+)'] = 'default/Gallery_controller/view/$1';
And in your template file:
<a href="<?php echo base_url('account/gallery/'.$imageDetail['imageId']); ?>">
<img src="" />
</a>
Then you can access directly in your gallary controller in view function $id.
eg:
class Gallery extends MY_Controller {
public function view($id){
// Your Image ID = $id;
}
}
Set this url http://my-domain-name/account/gallery/1 proper in href
<a href="<?php echo site_url('account/gallery/view'.$imageDetail['imageId']); ?>">
<img src="" />
</a>
Replace
<a href="<?php echo base_url('account/gallery/view'); ?>?id=<?php echo $imageDetail['imageId']; ?>">
with
<a href="<?php echo base_url();?>account/gallery/view/<?php echo $imageDetail['imageId']; ?>">
Check your config.php
$config['enable_query_strings'] = true;
to
$config['enable_query_strings'] = false;
In this try this (:any)
$route['account/gallery/(:any)'] = 'default/gallery_controller/view/$1';
Or
$route['account/gallery/view?(:any)'] = 'default/gallery_controller/view/$1';
In the routes lower case
This code is make your url like http://domain-name/account/gallery/1
Try this:
<a href="<?php echo base_url();?>account/gallery/view/<?php echo $imageDetail['imageId'];?>">
<img src="" />
</a>
How do you change the logo to link to the home URL for all pages except one? I want one page to link to another page when the logo is clicked.
Here is the PHP code for the logo:
<div class="section-boxed section-header">
<?php do_action('pexeto_before_header'); ?>
<div id="logo-container">
<?php
$logo_image = pexeto_option('retina_logo_image') ? pexeto_option('retina_logo_image') : pexeto_option('logo_image');
if(empty($logo_image)){
$logo_image=get_template_directory_uri().'/images/logo#2x.png';
}
?>
<img src="<?php echo $logo_image; ?>" alt="<?php esc_attr(bloginfo('name')); ?>" />
</div>
What about creating a second section of PHP - with a slightly different DIV ID that is called when that paticular page is loaded, rather than this one which is called on all the other pages,
Copy, paste, change DIV ID <div id="logo-container2">, change link address.
In HTML - on the single page that takes them elsewhere - call
<div id="logo-container2">
Would that work?
Try to use template_tag is_page as condition
<div class="section-boxed section-header">
<?php do_action('pexeto_before_header'); ?>
<div id="logo-container">
<?php
$logo_image = pexeto_option('retina_logo_image') ? pexeto_option('retina_logo_image') : pexeto_option('logo_image');
if(empty($logo_image)){
$logo_image=get_template_directory_uri().'/images/logo#2x.png';
}
// Default logo url to home
$logo_url = esc_url(home_url('/');
// if is page about or id 5 anything inside is_page()
if(is_page('about') $logo_url = esc_url(home_url('about');
?>
<img src="<?php echo $logo_image; ?>" alt="<?php esc_attr(bloginfo('name')); ?>" />
</div>
I believe you should be able to use the get_permalink method to check which page you are on, and use an if statement to tell it what the href should be.
<a href="<?= (get_permalink() == '/my-page') ? esc_url(home_url('/go-to-page')) : esc_url(home_url('/')); ?>">
Haven't tested this, but it should work.
In this little snippet of code ,i show how i take the "foto1" column of my database and transfer the value of it to a variable in c# named $foto.
The $foto contains the path of the image corresponding to the product that is showing up. Ive tried to copy and paste the path and ditch out the php part and it works. But when i put it in img src it gives me like the broken image thing.And i cant figure out why it does that.
All help is aprecciated .
Have a nice day :)
<div class="row shop_box-top">
<?php
$ligaBD=odbc_connect('basededadospap','','');
$sql="SELECT * FROM produto WHERE nome_produto LIKE '%ADIDAS%'";
$resultado=odbc_exec($ligaBD,$sql);
?>
<div class="row shop_box-top">
<?php
while (odbc_fetch_row($resultado))
{
$nome = odbc_result($resultado,2);
$preco= odbc_result($resultado,4);
$foto = odbc_result($resultado,9);
?>
<div class="col-md-3 shop_box"><a href="stansmithflatwhite.html">
<img src="<?php echo $foto; ?>" class="img-responsive" alt=""/>
<span class="new-box">
<span class="new-label">Novo</span>
</span>
<div class="shop_desc">
<h3><?php echo $nome; ?></h3>
<span class="actual"><?php echo $preco; ?></span><br>
</div>
</a></div>
<?php }?>
depends of what path contains the $foto var. If is the absolute path, you have to retrive the relative path.
Try also to append an / or an http[s] in front of the path
<img src="/<?php echo $foto;?>">
So it would be : //path/to/photo
As I can see it in your comment, your image paths contain spaces, so a possible solution can be to use urlencode() before echoing them.
Try passing full path to img tag like http://localhost/xyz/images/Cal�ado/Adidas/Homem/Stan Smith/ADIDAS STAN SMITH - RED/ch-adidas-stan-smith-red-5.jpg.
Replace "localhost/xyz" with your website directory path.
hi i want to just load the view page using variable not by direct name
here is my code:-
function load_views()
{
$this->load->model('test_model');
$data=$this->test_model->getMenu();
foreach($data as $data_menu) {
echo $data_menu->views;
$this->load->view($data_menu->views);
}
}
output :
test_view
An Error Was Encountered Unable to load the requested file: .php
actually it takes the value from db but it did not call the view file which is present in the view folder.
this is my view page :
<div class="panel-heading">
<h3 class="panel-title">Dashboard</h3>
</div>
<br/>
<div class="row">
<?php
$count = 0;
foreach($m as $data_menu){
if(($count% 4== 0))
{
?>
<div class = "row"></div>
<?php
}
?>
<div class="col-md-3">
<!--<a href="<?/*php echo base_url()*/?>index.php/<?php/* echo $data_menu->views*/?>">-->
<a href="<?php echo base_url()?>index.php/dn_login_controller/load_views">
<img class="img-rounded" src="" height="80" width="80" />
<div class="caption">
<h3><?php echo $data_menu->function_name; ?></h3>
</div>
</a>
</div>
<?php
$count++;
}
?>
</div>
</div>
Now in the view i want load views dynamically but i cant...
please help me.....
If you var_dump($data) you will see that it has an empty value somewhere in the array.
As kumar_v said in a comment, try to check for empty values
foreach($data as $data_menu) {
if(!empty(trim($data_menu->views)))
$this->load->view($data_menu->views);
}
This issue might be because, you cannot just directly load multiple views from single function/controller, when you just load view CI will send it to browser.
There are two other workaround for this :
Pass 2nd parameter NULL & 3rd parameter TRUE while loading your menu views, which will create your html as data instead of sending it to browser. Refer this link : codeigniter: loading multiple views
Create a view file, pass your data to that view & on that view execute for loop & load all your views.
I have a problem here that deals with the displaying of a photo inside a variable within a div class.
Here's my code below and help me find solutions. Thanks
if($newimage){
$url = 'http://www.client.jaobuilders.com/uploads/profile_picture/upload_photos/$newimage';
} else {
$url = 'http://www.client.jaobuilders.com/images/blank_photo.jpg';
}
return '
<div class="comment">
<div class="avatar">
'.$link_open.'
<img src="'.$url.'" width="50px" height="50px"/>
'.$link_close.'
</div>
$newimage is a variable and the value will depend on the user who logged in.
I really don't know what to do. Help me.
You have a problem with quotes - some of them are lacking. Also you did not close <div> tag:
return '
<div class="comment">
<div class="avatar">
'.$link_open.'
<img src="'.$url.'" width="50px" height="50px"/>
'.$link_close.'
</div>
</div>';
I can only hope this return statement is enclosed in some kind of function or method. Or at least it is the only return statement in a file that has been properly included somewhere (like $my_divs = include('some_file.php');).