how to navigate the particular page in codeigniter - php

i have admin panel side bar like as follow
<li class="<?= (uri_string() ==
"admin/customer_personal/listcustomerpersonal")?"active":NULL;?>">
<a href="<?php echo
base_url('admin/customer_personal/listcustomerpersonal'); ?>">
<i class="fa fa-users fa-lg"></i> View Customer Personal
</a>
</li>
my view file is locate in admin/customer_personal/listcutomer.php then my controller file is
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Cus_personal extends MX_Controller
{
function __construct()
{
if($this->session->userdata('isLoggedIn')==FALSE)
{
redirect('auth','refresh');
}
//$this->load->model('model_customer_personal');
$this->load->library('api_lib');
}
function index()
{
$this->listcustomerpersonal();
}
function listcustomerpersonal()
{
//$data['customers']=$this->load->get_customerall();
//$this->theme_lib->data = $data;
$this->theme_lib->view ='customer_personal/listcustomerpersonal';
$this->theme_lib->title = 'D2D | Customer Attendance';
// $this->theme_lib->pageFoot
='customer_personal/listcustomerpersonalfoot';
//$this->theme_lib->pageHead
='customer_personal/listcustomerpersonalhead';
$this->theme_lib->render();
}
}
?>
then my view file is
<?php
echo '<h1>hai hello how are you</h1>';
?>
but i have an error as 404 page not found error but other page in this panels were worked.

I guess your controller file is also located on path admin/customer_personal/. If yes, then you need to change your change below line
<a href="<?php echo base_url('admin/customer_personal/listcustomerpersonal'); ?>">
to
<a href="<?php echo base_url('admin/customer_personal/Cus_personal/'); ?>">
Hope this helps.

Set the route for the url in config > routes as below
$route['admin/customer_personal/listcustomerpersonal'] = 'admin/cus_personal/listcustomerpersonal';
or change the url in the side bar like
<li class="<?= (uri_string() ==
"admin/customer_personal/listcustomerpersonal")?"active":NULL;?>">
<a href="<?php echo base_url('admin/cus_personal/listcustomerpersonal'); ?>">
<i class="fa fa-users fa-lg"></i> View Customer Personal
</a>
</li>

Related

My route somehow keep redirecting to wrong url

so
i try make a pos(point of sale) program using ci3
im trying add a feature where admin can make new menu and submenu
but something went wrong
when i goto controller "sistem"
my route show "sitename/sistem/sistem/menu" this route supposed to "sitename/sistem/menu". another controller also effected when i goto "dashboard" controller the route show
"sistem/dashboard"
this is sistem controller
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Sistem extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('M_menu');
$this->load->model('M_user');
if (!$this->session->userdata('email')) {
redirect('auth');
}
}
public function index()
{
$this->menu();
}
public function menu()
{
$data['judulpage'] = 'Manajemen Menu';
$data['datamenu'] = $this->M_menu->getmenus()->result_array();
$data['user'] = $this->M_user->getuserdata()->row_array();
$this->form_validation->set_rules('menutambah', 'Menu', 'required');
// $this->form_validation->set_message([
// 'required' => 'Field menu add harus diisi'
// ]);
if ($this->form_validation->run() == false) {
$this->load->view('template/header', $data);
$this->load->view('template/sidebar', $data);
$this->load->view('sistem/menu', $data);
$this->load->view('template/footer');
} else {
$menu['menu'] = $this->input->post('menutambah');
$this->M_menu->insertmenu($menu);
$this->session->set_flashdata('flash','Sukses');
redirect('sistem');
}
}
this is the sidebar.php i think this is the problem but i cant find the solution
<?php
$role_id = $this->session->userdata('role_id');
$queryMenu = "SELECT `user_menu`.`id`, `menu`, `icon_menu`
FROM `user_menu`
JOIN `user_access_menu` ON `user_menu`.`id` = `user_access_menu`.`menu_id`
WHERE `user_access_menu`.`role_id` = $role_id";
$menus = $this->db->query($queryMenu)->result_array();
?>
<!-- BEGIN: Main Menu-->
<div class="main-menu menu-fixed menu-dark menu-accordion menu-shadow" data-scroll-to-active="true">
<div class="main-menu-content">
<ul class="navigation navigation-main" id="main-menu-navigation" data-menu="menu-navigation">
<li class=" navigation-header"><span>MENU</span><i class=" feather icon-minus" data-toggle="tooltip" data-placement="right" data-original-title="Apps"></i>
</li>
<?php foreach($menus as $menu) : ?>
<?php
$menuid = $menu['id'];
$querysubmenu = "SELECT * FROM `user_sub_menu` WHERE `menu_id` = $menuid AND `is_active` = 1";
$submenus = $this->db->query($querysubmenu)->result_array();
?>
<li class=" nav-item"><i class="<?php echo $menu['icon_menu']; ?>"></i><span class="menu-title"><?php echo strtoupper($menu['menu']); ?></span>
<ul class="menu-content">
<?php foreach($submenus as $submenu) : ?>
<li>
<a class="menu-item" href="<?php echo $submenu['url']; ?>"><i class="<?php echo $submenu['icon']; ?>"></i><span><?php echo $submenu['title']; ?></span></a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
i take the url from database.
u can see from inspect mode, the href redirecting to sistem/menu which is coorect url but when i click it, it goto sistem/sistem/menu
You do not need to call double <?php ?> tag.
just do this
<?php echo base_url($submenu['url']); ?>
or simplify the echo syntax with
<?= base_url($submenu['url']); ?>
fixed href="<?php echo base_url(); ?> i add / this before php tag but somehow it worked but still directing to wrong url localhost/sistem/menu it supposed to localhost/site/sistem/menu, so i add base_url to add my sitename and it work, thx
<li>
<a class="menu-item" href="<?php echo base_url(); ?><?php echo $submenu['url']; ?>">
<i class="<?php echo $submenu['icon']; ?>"></i><span><?php echo $submenu['title']; ?></span></a>
</li>

can't get id from url with $_GET[url] in mvc architecture

I'm trying to make my own MVC Architecture and i'm stuck on getting id from url.
For example in the url, I have http://localhost/EdelweissMagazine /articles/edit/?id=66
but when I call print_r($_GET[url]) I only have
Array
(
[url] => articles/edit/
[id] =>
)
I can't understand why..
Here is my code. I hope you could help me to understand.
For explanations, I would like to make an update method : When clicking on the edit button, placed inside a photo (only if it is a user), the user goes to a form with datas already written to edit.
Thank you in advance
.htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9\-_\/]*)$ index.php?url=$1&id=$2 [NC,L]
I've used in the router that function index.php
call_user_func_array([$controller, $action], $url);
controller/Articles.php
class Articles extends Controller{
public function index(){
$article = $this->loadModel('Article');
$articles = $article->getAll(); //getAll() : $sql="SELECT * FROM ".$this->table;
$this->render('index', ['articles' => $articles]);
}
public function edit(){
print_r($_GET);
}
}
Views/articles/index.php
<section class="gallery">
<?php
$articleLength = count($articles);
$count = 1; ?>
<?php while($count < $articleLength): ?>
<?php
if($count%4 == 1){
?>
<div class="column">
<?php
}
?>
<div class="wrap-img">
<img class="items-gallery"
src="<?php echo htmlspecialchars(SCRIPT_ROOT.'/'.$articles[$count]['picture'], ENT_QUOTES); ?>"
alt="<?php echo htmlspecialchars($articles[$count]['title'], ENT_QUOTES);?>"
/>
<?php
/*************** Code to edit an article ***************/
if(isLogged()) {
?>
<a class="action-icons" href="<?php echo SCRIPT_ROOT.'/articles/edit/?id='.$articles[$count]['id']; ?>"><i class="fas fa-pencil-alt"></i></a>
<a class="action-icons" href="<?php echo SCRIPT_ROOT; ?>"><i class="fa fa-trash"></i></a>
<?php
}
?>
/**********************************************/
</div>
<?php
if($count%4 == 0){
?>
</div>
<?php
}
$count = $count + 1;
endwhile;
?>
</section>
<div id="modal">
<span id="closeModal"><i class="fas fa-times"></i></span>
<img class="modal-content" id="img01" />
<div id="caption"></div>
<i class="fas fa-chevron-left"></i>
<i class="fas fa-chevron-right"></i>
</div>

Get value of a button to change in CodeIgniter using logic from controller?

I'm trying to change the value of a button between login/logout depending on if a session is in progress. The logic works perfectly. The issue I have is sending the actual "login" or "logout" label from the controller (Navigation) to the view (navigation). How do I do this? I have tried sending over TPL but the button is blank (although functions upon being clicked).
Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
// start the session
if(isset($_SESSION)){
session_start();
}
var $TPL = array();
if(isset($_SESSION["accesslevel"])){
$this->TPL["outPut"] = "Logout";
}
else{
$this->TPL["outPut"] = "Login";
}
class Navigation extends CI_Controller {
public function index()
{
$this->template->show('navigation');
}
}
view:
<ul>
<li>Home</li>
<li>Members</li>
<li>Admin</li>
<li><?php $outPut ?></li>
</ul>
Is $output accessible in your view?
You need to pass $TPL from controller to your view and Write session code inside constructor.
Constructor :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Navigation extends CI_Controller {
private $TPL = array();
function __construct() {
parent::__construct();
if(isset($_SESSION["accesslevel"])){
$this->TPL["outPut"] = "Logout";
}
else{
$this->TPL["outPut"] = "Login";
}
}
public function index()
{
$this->template->show('navigation', $this->TPL);
}
}
why don't check in view if there's a session? if the answer is yes that means that the user is logged and you'll show him the log-out button, otherwise you'll show him the login button.
<?php if ($this->session->userdata('id')){ ?>
<div class="float-right">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<?php echo anchor('User/user_profile/'.$this->session->userdata('id'), 'My profile', array('class' => 'nav-link')); ?>
</li>
<li class="nav-item">
<?php echo anchor('User/logout', 'Log out', array('class' => 'nav-link')); ?>
</li>
</ul>
</div>
<?php }else{ ?>
<div class="float-right">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<?php echo anchor('User/login', 'Login', array('class' => 'nav-link')); ?>
</li>
<li class="nav-item">
<?php echo anchor('User/register', 'Register', array('class' => 'nav-link')); ?>
</li>
</ul>
</div>
<?php } ?>

php session expired on root domain

I have Created Session on subdomain but right now i am unable to access session variable on Root domain
Login Page : myaccount.javaignite.com //authenticate login
Home: page
www.javaignite.com // here i am unable to get the value
myaccount.javaignite.com/Auth.php
Calling by ajax from index.php
<?php
$sess_name = session_name('app');
session_set_cookie_params(0, '/', '.javaignite.com');
session_start();
if($_POST){
$profile_id =$_POST["profile_id"];
$profile_fullname =$_POST["profile_fullname"];
$profile_img =$_POST["profile_img"];
$profile_email =$_POST["profile_email"];
$_SESSION["profile_id"] =$profile_id;
$_SESSION["profile_fullname"] =$profile_fullname;
$_SESSION["profile_img"] =$profile_img;
$_SESSION["profile_email"] =$profile_email;
$redirect_url ="http://javaignite.com";
if(isset($_SESSION["redir_url"])){
$redirect_url =$_SESSION["redir_url"];
}
echo $redirect_url;
die;
}
?>
javaignite.com/navigation.php
which is include in myaccount.javaignite.com/index.php and index.php (in root)
<?php
print_r($_SESSION);
if(isset($_SESSION["profile_id"])){
?>
<ul class="nav navbar-nav navbar-right" style="margin-right:10px;">
<li class="dropdown selected">
<a class="" href="http://account.javaignite.com/profile"> <i class="fa fa-sign-in"></i>
<?php echo $_SESSION["profile_name"]; ?> </a>
</li>
</ul>
<?php
} else {
?>
<ul class="nav navbar-nav navbar-right" style="margin-right:10px;">
<li class="dropdown selected">
<a class="" href="http://account.javaignite.com/"> <i class="fa fa-sign-in"></i> Login/Signup </a>
</li>
</ul>
<?php
}
?>
You need to update php.ini file. Please read following older question links
1.Allow php sessions to subdomains
2.Session variable from subdomain to main domain

How to add active class to codeigniter hyperlinks?

I know this question comes across a lot, but I just can't figure out how to do this using the, already answered posts.
I have a header with navigation links. I would like to add class="active" to the link that's active at the moment.
How could I do this if I have the following navigation?
<nav>
<ul id="main_nav">
<li class="home">
<a href="search">
<i class="icon-search"></i>
<span>BEDRIJF ZOEKEN</span>
</a>
</li>
<li class="categorie">
<a href="categorieen/all">
<i class="icon-list-ul"></i>
<span>CATEGORIE</span>
</a>
</li>
<li class="aanbieding">
<a href="aanbiedingen">
<i class="icon-shopping-cart"></i>
<span>AANBIEDING</span>
</a>
</li>
<li class="vacature">
<a href="vacatures">
<i class="icon-copy"></i>
<span>VACATURE</span>
</a>
</li>
<li class="agenda">
<a href="agenda">
<i class="icon-calendar"></i>
<span>AGENDA</span>
</a>
</li>
<li class="contact">
<a href="contact">
<i class="icon-envelope"></i>
<span>CONTACT</span>
</a>
</li>
</ul>
</nav>
I tried this, but it did not work:
<script>
$(function() {
var href = $(this).find('a').attr('href');
alert(window.location.pathname)
if (href === window.location.pathname) {
$(this).addClass('active');
}
});
</script>
Maybe there's a better Codeigniter-ish way?
try this one.i think no need of javascript or jquery.
If you are using codeigniter then you can use URI Class.
<li class="home">
<a class="<?php if($this->uri->segment(1)=="search"){echo "active";}?>" href="<?=base_url('search')?>">
<i class="icon-search"></i>
<span>BEDRIJF ZOEKEN</span>
</a>
</li>
please let me know if you face any problem
I created a helper and saved it into the helper directory named as "menu_helper.php":
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
if(!function_exists('active_link')) {
function activate_menu($controller) {
// Getting the class instance.
$ci = get_instance();
// Getting the router class to actived it.
$class = $ci->router->fetch_class();
return ($class == $controller) ? 'active' : '';
}
}
Then in config/autoload.php, I added "menu" as a helper on line 91.
The last step is to put the code for print the "active" class when accessing the page (i.e. Login Page):
<li class="<?php echo activate_menu('login'); ?>">
<?php echo anchor('login', 'Login'); ?>
</li>
if (href === window.location.pathname) {
$('a[href='+ href +']').addClass('active');
}
Try this one:
<a class="<?=(current_url()==base_url('search')) ? 'active':''?>" href="<?=base_url('search')?>">

Categories