add segment before controller without changing base url - codeigniter

I have a url like this
localhost/codeIgniter/Depan?lang=id
and I want to make it like this
localhost/codeIgniter/id/Depan
where localhost/codeIgniter is the base_url, /id is parameter for language, and /Depan is the controller name. But since I change the url as the second one. The base_url is changed to localhost/codeIgniter/id. So everytime I pass images location like assets/image/pic1.jpg from javascript. The link in html become localhost/codeIgniter/id/assets/image/pic1.jpg. And the file that actually stored in codeIgniter/assets/images folder is can't accessed. Ive already set the
$config['base_url'] = 'localhost/codeIgniter'
I wish I could use the second url without changing the base url
HTML
<div class="picture container">
<img id="slide" src="">
<div class="desc">
<div id="text">
<p></p>
</div>
<div id="text">
</div>
</div>
<div onclick="prev()" class="prev">
<img src="<?php echo base_url();?>assets/button/prev.png">
</div>
<div onclick="next()" class="next">
<img src="<?php echo base_url();?>assets/button/next.png">
</div>
<div class="pics">
</div>
<script> var sldrpic = <?php echo json_encode($sldrpic); ?>;</script>
<script src="<?php echo base_url();?>javascript/sldr_home.js"></script>
</div>
Javascript
function firstslide() {
if (!document.images)
return
document.getElementById('slide').src = slideimages[step].src;
document.getElementById('slide').alt = sldrpic[step].nama;
document.getElementById('text').childNodes[1].innerHTML = sldrpic[step].nama;
}
with the javascript I want to pass the slideimages[] array that contain folder path assets/image/pic.jpg to the
<img id="slide" src="">

I have put base url variable in html as shown below.
<div class="picture container">
<img id="slide" src="">
<div class="desc">
<div id="text">
<p></p>
</div>
<div id="text">
</div>
</div>
<div onclick="prev()" class="prev">
<img src="<?php echo base_url();?>assets/button/prev.png">
</div>
<div onclick="next()" class="next">
<img src="<?php echo base_url();?>assets/button/next.png">
</div>
<div class="pics">
</div>
<script> var sldrpic = <?php echo json_encode($sldrpic); ?>;</script>
// echo base url from php
<script> var base_url ="<?php echo base_url();?>"; </script>
<script src="<?php echo base_url();?>javascript/sldr_home.js"></script>
</div>
javascript
function firstslide() {
if (!document.images)
return
// note: base_url is variable. not function.
document.getElementById('slide').src = base_url + slideimages[step].src;
document.getElementById('slide').alt = sldrpic[step].nama;
document.getElementById('text').childNodes[1].innerHTML = sldrpic[step].nama;
}

Related

Error link to another page with href (Error with %E2%80%8B code in my localhost url)

I tried to make a button that linked to another page. But it seems so weird because it shows an error when the button was clicked.
The requested URL /​index.php/fin/bukti_kas/add_dokkas was not found on this server.
And when I tried to copy the URL from the browser it gave me this strange URL:
http://localhost/%E2%80%8Bindex.php/fin/bukti_kas/add_dokkas
There is %E2%80%8B, and that what makes the link not work.
My controller (add_dokkas.php):
public function index()
{
if($this->model_dokkas->logged_id())
{
$data_pribadi['test'] = array(
$usrid = $this->session->userdata('USRID'),
$employee_id = $this->session->userdata('EMPLOYEE_ID'),
$passwd = $this->session->userdata('PASSWD'),
$ket_jbt = $this->session->userdata('KET_JBT'),
$ket_gas = $this->session->userdata('KET_GAS')
);
$this->load->view('fin/bukti_kas/v_add_dokkas', $data_pribadi);
}else{
redirect("fin/bukti_kas/login");
}
}
And my view (v_add_dokkas.php):
<div class="container py-2">
<div class="col-md-12">
<h2 class="text-center mb-2">Pembuatan Dokumen Bukti Kas/Bank(NEW)</h2>
<div class="row" style="padding-top: 20px">
<div class="" style="padding:10px; margin: 0px">
<a class="btn btn-primary" href="<?php echo base_url();?>​index.php/fin/bukti_kas/add_dokkas" role="button">Link</a>
</div>
</div>
<div id="grid"></div>
</div>
</div>
My config base :
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['index_page'] = '';
Why do I get this error/strange URL?
I've been solving my problem with this:
<?php echo anchor(site_url('index.php/fin/bukti_kas/dokkas/add_dokkas'), 'Create', 'class="btn btn-primary"'); ?>

AJAX loading img

I am new to AJAX/Jquery, what is the best way to put a loading img while the page is is still on load ?
here is my code:
<div class="container">
<div class="row">
<div class="col-lg-12">
<button class="btn btn-info btn-lg">Load More Page...</button>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("#box").load("page2.php");
});
});
</script>
Please check below link
There is example
How can I create a "Please Wait, Loading..." animation using jQuery?
You can simply use ajax- methods like ajaxStart, ajaxStop
Javascript code:
$(document).ready(function(){
$(document).ajaxStop(function(){
$('#loadingIndicator').hide(500);
});
$( document ).ajaxStart(function() {
$('#loadingIndicator').show();
});
}
HTML code:
<div id="loadingIndicator" style="display:none;z-index:100;">
<img src="loading-big.gif" alt="" />
</div>

Fancy box will not work

here is my codepen:
`
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>
<div class="container">
<div class="row">
<div class="col-sm-9" id="mainContent">
<a class="fancybox" rel="group" href="img/1.jpg"><img src="img/1a.jpg" alt="" /></a>
<a class="fancybox" rel="group" href="img/me2.jpg"><img src="img/me3.jpg" alt="" /></a>
</div>
</div>
</div>
`
http://codepen.io/anon/pen/gMbmzZ
I can't get this fancy box to work for the life of me. I have checked the file path for the css and the javascript and those should be good. I have also made sure to import jquery into my html file.
no matter what i do i can't get it to work. any help is appreicated.

Codeigniter - Inserting Ads after each x rows

I want to insert advertisements after each X rows returned from database.
My Controller looks like this:
class Home extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->database();
$this->load->library('parser');
$this->load->helper('url');
$this->load->helper('download');
$this->load->model('Categorii');
$this->load->model('Comentarii');
}
public function index($pages = ""){
$c_ar = $this->Categorii->iaCategorii();
$sql = (!empty($pages)) ? "SELECT * FROM bancuri WHERE categorie = '" . $c_ar[$pages] . "'" : "SELECT * FROM bancuri";
$dbQ = $this->db->query($sql);
$renderData = array("bancuri" => $dbQ->result_array(), "ad" => "<img src='http://placehold.it/350x150'>"); //Se stocheaza datele intr-o matrice
$this->parser->parse('pages/bancuri',$renderData);
}
And view looks like this:
<div class="col-lg-8 col-sm-12 col-xs-12">
{bancuri}
{ad}
<div class="corgi_feed_well">
<div class="individual_feed_item">
<div class="feed_item">
<div class="feed_body">
<div class="row">
<!--
<audio controls>
<source src="<?php echo $this->config->item('base_url'); ?>resources/mp3/{mp3}" type="audio/mpeg">
</audio>
-->
</div>
<div class="row">
<div class="feed_profile_pic">
<span class="label label-info">Rating: {rating}</span>
<div class="clearfix"> </div>
<button type="button" class="btn btn-success">Like</button>
</div>
<div class="feed_text">
<p class="well">{banc}</p>
</div>
</div>
</div>
<div class="comment_area">
<p>Adauga un comentariu</p>
<form>
<textarea rows="3" class="span6"></textarea><br/>
<input type="submit" class="btn" />
</form>
</div>
<hr class="feed_hr" />
<div class="bottom_meta">
<div class="row">
<div class="bottom_left">
<div class="share_wrapper">
<div class="share"><i class="icon-heart"></i></div>
<div class="share_hidden">
<ul class="hover_heart">
<span class="internal_heart"><i class="icon-heart"></i> Trimite bancul pe</span>
<div class="social_links">
<li><span><i class="icon-twitter"></i> Twitter</span></li>
<li><span><i class="icon-facebook"></i> Facebook</span></li>
<li><span><i class="icon-pinterest"></i> Pinterest</span></li>
</div>
</ul>
</div>
</div>
</div>
<div class="bottom_left">
Descarca <span class="label label-primary">{descarcari} descarcari</span>
{comentarii} comentarii<br>
</div>
<div class="bottom_right">
{autor} <span>|</span> Adauga comentariu <span>|</span> {data}
</div>
</div>
</div>
</div>
</div>
</div>
{/bancuri}
The problem is that at the moment, it displays the ad (simple image atm) for every database row.
Regardless of the code you posted, In short, you just add a counter and use modulo.
so something like
$arr = range('a','z');
$n = 0;
foreach ($arr as $item)
{
if($n % 4 ==0) // 4 equals to the interval between ads
echo 'print banner';
$n++ ;
}
this will print an ad, or whatever you want, every 4 lines, play around with the numbers as you see fit and add a zero check if you don't like ads to appear in the first line.

How to add attribute values to the footer in Magento, as a list?

My products in Magento have attribute Brand. What I need to do is to display a list of Brands in the footer.Something like: Our Brands: Brand 1, Brand 2, Brand 3...
As far as I understand I need somehow retrieve values from Advanced search and display them in footer as a list, but I don't know how to do it. Does anybody have solution for this?
There are several steps to follow
here i am giving detail instruction how to add your custom attribute at footer.
1. you have to create on block to get all your brand product with assign your custom attribute
for block.
$attributes = Mage::getSingleton('eav/config')
->getEntityType(Mage_Catalog_Model_Product::ENTITY) // pass your attribute id
->getAttributeCollection()
->addSetInfo();
foreach ($attributes as $attribute)
{
if ($attribute->usesSource())
{
echo "{$attribute->getFrontendLabel()}:\n";
foreach ($attribute->getSource()->getAllOptions() as $option)
{
echo " {$option['label']}\n";
}
echo "\n";
}
}
above is print logic you should have to store it one array in return with one variable.
2. create view file in your theme for display purpose and call that block function in that home_logo file.
<?php $_brandsCollection = $this->getBrandsLogoCollection();?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Brands') ?></span></strong>
</div>
<div class="block-content" >
<div id="Carousel2" class="carousel">
<div class="button navButton previous" style="display:none;">Back</div>
<div class="button navButton next" style="display:none;">More</div>
<div class="container">
<div class="items">
<?php foreach ($_brandsCollection as $_brand): ?>
<div class="item">
<div class="key caption"></div>
<div class="icon">
<img class="brand-base-logo" alt="<?php echo $_brand->getBrandLogo() ?>" src="<?php echo $_brand->getBrandLogo(); ?>" width="50" height="50">
</div>
<div class="picture">
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div> <!-- end block content-->
</div>
3. Assign that file to footer using your_layout.xml with reference before footer.
<reference name="footer">
<block type="brand/left" name="brands_logolist" before="-" template="brand/home_logo.phtml" />
</reference>
Hope you can understand my logic.

Resources