Reputation: 495
I have many views in a folder in views folder, for example in views/admin folder.
When I code
if (!empty($users->users)):
foreach ($users->users as $user) {
$link = site_url('ContentController/showActivities/' . $user->id);
$what = $user->banned == 0 ? 'b':'u';
$banned_t = $user->banned == 0 ? 'Banned':'Un-banned';
echo '<tr id="user_'.$user->id.'">';
echo '<td><div class="userimg"><img src="' . $user->profile_pic->medium . '"></div></td>';
echo '<td>'.$user->name . '</td>';
echo '<td>';
echo $user->last_login == '' ? 'never' : $user->last_login;
echo '</td>';
echo $user->banned == 0 ? '<td><span class="label label-success">Active</span></td>' : '<td><span class="label label-danger">Banned</span></td>';
echo '<td>'.$user->email.'</td>';
echo '<td><div class="btn-group">
<button type="button" onclick="Buckty.user.edit($(this));" data-toggle="modal" data-target="#editUser" data-id="'.$user->id.'" class="btn btn-danger">Edit</button>
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a onclick="javascript:ref('.$user->id.')">Show Activities</a></li>
<li><a onclick="Buckty.user.ban($(this));" data-id="'.$user->user_hash.'" data-what="'.$what.'">'.$banned_t.'</a></li>
<li><a onclick="Buckty.user.remove($(this));" data-id="'.$user->id.'">Delete</a></li>
</ul>
</div></td>';
echo '</tr>';
}
endif;
And this is the code that i want to redirect to controller
<li><a onclick="javascript:ref('.$user->id.')">Show Activities</a></li>
Javascript:
function ref(id) {
window.open('ContentController/showActivities/'+id, '_blank');
}
But, when i click "Show Activities" menu, it always redirect to http://localhost/file-sharing/admin/ContentController/showActivities/1
and it doesn't redirect to ContentController/showActivities
controller. It should redirect to that controller if the url is http://localhost/file-sharing/ContentController/showActivities/1
Anybody know what should I do in this case? Thanks in advance.
Upvotes: 1
Views: 1094
Reputation: 1591
Being Owner
of this platform. Let me clear you few things. Site url is not being defined by base_url()
or site_url()
for functions and compatibility reasons.
First of all , i would not recommend you to not use controller names , try to organise and make routes for your controllers inside routes.php
but now let's talk about your problem.
site_url()
is your current url you are on. But you have very simple access to global settings for everything.
Introduction to global variables
so according to your problem , you should be using $site->site_url
and not site_url();
basically change this :
$link = site_url('ContentController/showActivities/' . $user->id);
to this
$link = $site->site_url.'ContentController/showActivities/' . $user->id;
or if we talk about javascript then global variable for javascript is also there. you should be using site_url
as site link so edit the below :
function ref(id) {
window.open('ContentController/showActivities/'+id, '_blank');
}
to this
function ref(id) {
window.location.replace(site_url + 'ContentController/showActivities/'+id, '_blank');
}
here is introduction to global variables for javascript :
site_url
|| this contains your site url (from site settings ) user_data
|| this contains current user's data (everything only password is not there ) site_info
|| this contains site settings data.tran
|| this contains multi language translations current_folder
|| this contains current folder's hash id , on which you are currently
current_folder
is 0 if it's on root folder , else it if folder
if it's on un-functional view. Upvotes: 1
Reputation: 924
Try this :
function ref(id) {
window.open('<?php echo base_url()?>ContentController/showActivities/'+id, '_blank');
}
Upvotes: 0