I have two view one for menu and other for page content.
header
cart
In header cartpopup
is an array key which contains cart data which which will only popup when user clicks cart icon, but here when the page is rendered this cartpopup contents get printed before html is generated.
This code gets printed before html generated on the page:
<li>
<img src="1550847861_Hydrangeas.jpg class="cart-thumb" alt="">
<div class="cart-item-desc">
<h6>Item1</h6>
<p>1x - <span class="price">475</span></p>
</div>
<span class="dropdown-product-remove"><i class="icon-cross"></i></span>
</li>
then html and body contents is generated
header.php
<div class="cart">
<i class="ti-bag"></i><span class="cart_quantity"><?php echo $tot_cart;?></span>
<ul class="cart-list">
<?php echo $cartpopup; ?>
</ul>
</div>
Controller:
public function index() {
$data['output_cart']= $this->show_cart();
$tot_cart=$this->cart->total_items();
$data_menu = $this->category_menu();
$output_cart_popup= $this->load_cart_header_pop();
$this->load->view('header',['menudata'=>$data_menu,'tot_cart'=>$tot_cart,'cartpopup'=>$output_cart_popup]);
$this->load->view('cart',$data);
}
Screenshots:
You just have to use the third param as "true", as in:
$subView = $this->load->view(YOUR_VIEW, YOUR_DATA_ARRAY, true);
$params = array(
YOUR_DATA_ARRAY,
'subView' => $subView
);
$this->load->view(YOUR_VIEW, YOUR_DATA, true);
That way you will have your view preloaded in memory only, then you just have to pass the view in the params to the main view and finally echo it inside your main view, as in:
echo $subView;
Related
I have a site that uses query strings to retrieve the data like so:
<div id="menu-sort-dropdown" class="search-filter-item">
<p><?php echo $query_sort_title; ?></p>
<ul class="dropdown-menu">
<li>Newest</li>
<li>Oldest</li>
<li>Alphabetically</li>
</ul>
</div>
<div id="menu-category-dropdown" class="search-filter-item">
<p><?php echo $query_category_title; ?></p>
<ul class="dropdown-menu">
<li>All</li>
<li>Coaching</li>
<li>Conversation</li>
<li>Craft</li>
<li>Creativity</li>
</ul>
</div>
It works great getting the data like:
teachings/?sort=SORT_NAME_ASC
or
teachings/?category=Creativity
but I can do both like:
teachings/?category=Creativity&sort=SORT_NAME_ASC
I can't wrap my head around how to add that. If I just append the strip it will become a mess.
The following code doesn't 'duplicate' the values in the url if you keep clicking the category or sort. It's made to copy/paste and run.
// to check the values
echo '<pre>';
print_r($_GET);
echo '</pre>';
echo '<hr>';
function foo($type, $value){
$args = $_GET;
$args[$type] = $value; // prevent duplication
return http_build_query($args); // returns new query string
}
?>
SORT_DATE_LIT_ASC
<br>
SORT_NAME_ASC
<br>
Coaching
<br>
Conversation
You can also have a code to remove any of those. Add it right after the previous code (also copy/paste). Take a look:
<?php
function bar($type){
$args = $_GET;
unset($args[$type]);
return http_build_query($args); // returns new query string
}
?>
<hr>
Remove SORT
<br>
Remove CATEGORY
As for now your dropdown element do a simple action - go to provided url. If you want to select a few values then your elements should store selected value instead of open url. You can do this with for example this JS code
var menus = [];
function addElement(type, element) {
menus[type] = element;
}
The type above is number index of your menu type. For example 0 can be for sort and 1 for category - this is for ensure that you can select only one value from menu type. Now you can replace your code with something like this
<div id="menu-sort-dropdown" class="search-filter-item">
<p><?php echo $query_sort_title; ?></p>
<ul class="dropdown-menu">
<li>Newest</li>
<li>Oldest</li>
<li>Alphabetically</li>
</ul>
</div>
<div id="menu-category-dropdown" class="search-filter-item">
<p><?php echo $query_category_title; ?></p>
<ul class="dropdown-menu">
<li>All</li>
<li>Coaching</li>
<li>Conversation</li>
<li>Craft</li>
<li>Creativity</li>
</ul>
</div>
To go to the prepared URL you need to add another element like for example a button (or something else with calling openUrl function after mouse click)
<input type="button" onclick="openUrl('?')" value="Go to URL">
And the JS code for openUrl function
function openUrl(prefix) {
var url = prefix + menus.join('&');
document.location.href = url;
}
I have this div content in my header.php file contained in application/themes/custom_name/elements
<?php defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('elements/header_top.php');
$cl_txt = $c->getAttribute('client_login_txt');
$cl_url = $c->getAttribute('client_login_url');
?>
......
<div class="login">
<a href="<?php echo $cl_url ?>" target="_blank">
<button type="button" class="btn-login"><?php echo $cl_txt ?></button>
</a>
</div>
I would like to change the link contained in the div.
Where can I do it?
There are two Page Attributes, the link URL is called Client Link URL and the link text is called Client Link Text, I was able to edit this by going to Full Sitemap and click on the page I am trying to change and select Attributes.
I am trying to insert a custom tag after H3 tag with a certain class by inserting code into my theme's function.php file. Below is what I am doing but unable to achieve it.
If I have this, showing on a page currently:
<h3 class="title">TITLE HERE</h3>
<div class="desc">
I would like to insert a tag after h3 tag. Below is what I am trying to insert intp my theme functions.php file:
echo '<h3 class="title">TITLE HERE</h3>
<a tooltip="This is a test">TEST</a>
<div class="desc">'
As a result, I am just getting 'TEST' on the top of the page instead of showing it after the h3 tag.
Can you try this first.
Add **<div style="clear:both;"></div>** after your closing </h3> tag
OR
I think you are creating shortcode in function.php file. If you directly echo in your function then this problem will arise. First you assign the value to variable which you want to echo and then return this variable.
Eg:
function my_fun(){
$text='<h3 class="cuzd-title"> TITLE HERE</h3> <div style="clear:both;">
</div> <a data-tooltip="THIS IS TEST">TEST</a>';
return $text;
}
add_shortcode( 'shortcode_name', 'my_fun' );
now where you want these to be display just use
echo do_shortcode('[shortcode_name]');
I'm trying to figure out how to add a css class to a <li> tag in my menu navigation. I'm using a template that gets included on every page of site. In the template is the menu navigation code. I need to set the css class on the <li> for the corresponding active page using PHP_SELF I presume?
Navigation looks like this
And this is what it should look like when the page is displayed that corresponds to the page that was clicked in the navigation menu.
Here is the navigation menu code
<!-- MENU BEGIN -->
<div id="menu">
<ul id="nav">
<li>Home</li>
<li <?php echo $class_current; ?>>Technician</li>
<li <?php echo $class_current; ?>>Programming</li>
</ul>
</div>
<!-- MENU END -->
Here is the PHP function I am trying to create
function classCurrent(){
if(dirname($_SERVER['PHP_SELF']) == true) {
echo ' class="current"';
}
else {
echo '';
}
$current = classCurrent();
return $current;
}
I know this is possible, I just can't figure it all out yet.
You may try specifying some base class that has variables for the corresponding menus. So like if you are requesting the technician page:
Class Activmenu {
public $technician = true;}
alternatively you may use superglobal variables but this is safer. And in the menu you can check for the true item
if(Activemenu->technician)? echo'class="activeclass"' : 0;
Checking urls you will run into problems, if later on you have to modify your url structure.
So it is really simple actually to do this. All that needs to be done is have a variable set on the active page above the <html> tag preferably.
Example:
<?php $currentPage = 'technician';
<html>
So now we have this variable set on the technician page above the html tag. Now to call it in the template page on the navigation menu <li> all that needs to be done is the following.
<?php if ($currentPage=="technician") echo " class=\"current\""; ?>
Now just need to repeat this step for each page of the website.
This was also answered here PHP navigation menu
and a real good tutorial on how to do it is here http://alistapart.com/article/keepingcurrent
As a result the navigation code will end up looking something like this
<!-- MENU BEGIN -->
<div id="menu">
<ul id="nav">
<li<?php if ($currentPage=="home") echo " class=\"current\""; ?>>Home</li>
<li<?php if ($currentPage=="technician") echo " class=\"current\""; ?>>Technician</li>
<li<?php if ($currentPage=="programming") echo " class=\"current\""; ?>>Programming</li>
</ul>
</div>
<!-- MENU END -->
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.