I made breadcums automatically on CodeIgniter but, on the user profile editing view, my uuid is shown as uri->segment. I think It will look cleaner without the uuid. How can I skip, delete or hide it?
MY url
http://localhost/myproject/user/edit/0004055ac42e42bcb57183646e84ff05
Breadcumbs with helper
HOME > User > edit > 0004055ac42e42bcb57183646e84ff05
I expect it
HOME > User > edit
Helper breadcumbs:
<?php
if(!function_exists('generateBreadcrumb')){
function generateBreadcrumb(){
$ci = &get_instance();
$i=1;
$uri = $ci->uri->segment($i);
$link = '
<ol class="breadcrumb">
<li><i class="fa fa-home"></i> Home</li>';
while($uri != ''){
$prep_link = '';
for($j=1; $j<=$i;$j++){
$prep_link .= $ci->uri->segment($j).'/';
}
if($ci->uri->segment($i+1) == ''){
$link.='<li class="active"><a href="'.site_url($prep_link).'">';
$link.=$ci->uri->segment($i).'</a></li> ';
}else{
$link.='<li><a href="'.site_url($prep_link).'">';
$link.=$ci->uri->segment($i).'</a><span class="divider"></span></li> ';
}
$i++;
$uri = $ci->uri->segment($i);
}
$link .= '</ol>';
return $link;
}
}
?>
Will this only happen after "User > edit"? If so, how about adding a conditional that looks for that sequence and ignores the segment if found?
I'd like to test this but I don't have a playground ready. See if this works for you:
if ( $i>1 && $ci->uri->segment($i) == 'edit' && $ci->uri->segment($i-1) == 'User' ) {
//just ignore this
} else {
if($ci->uri->segment($i+1) == ''){
$link.='<li class="active"><a href="'.site_url($prep_link).'">';
$link.=$ci->uri->segment($i).'</a></li> ';
}else{
$link.='<li><a href="'.site_url($prep_link).'">';
$link.=$ci->uri->segment($i).'</a><span class="divider"></span></li> ';
}
}
Another solution would be to check if strlen($ci->uri->segment($i)) equals 32. Of course this will only work if you expect uuid to always be 32 characters and no other URI segment to be that long.
Try this.its works only if you want to add your controller and method name in breadcrumb
$c=$this->router->fetch_class();;
$m=$this->router->fetch_method();
$link="";
$link.='<li><i class="fa fa-home"></i> Home</li>';
if($m!='index')
{
$link.='<li><a href="'.site_url($c).'">$c</li>
<li><a class="active" href="'.site_url($m).'">$m</li>';
}
else
{
$link.='<li><a class="active" href="'.site_url($c).'">$c</li>';
}
Related
Here is my Index:
<div class="page-sizer">
<a class="page numbers" href="{{$references->pagination(10)}}">10</a>
<a class="page numbers" href="{{$references->pagination(30)}}">30</a>
<a class="page numbers" href="{{$references->pagination(100)}}">100</a>
<button href="qweqwe.qweqwe" class="btn btn-info float-right>112e1e1e1e"></button>
</div>
My AdminreferenceController:
public function index()
{
$references = Reference::orderBy('priority', 'desc')->orderBy('id', 'desc')->paginate(50);
return view('admin.reference.index', ['references' => $references]);
}
and my Lengthawarepaginator:
public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
{
foreach ($options as $key => $value) {
$this->{$key} = $value;
}
$this->total = $total;
$this->perPage = $perPage;
$this->lastPage = max((int) ceil($total / $perPage), 1);
$this->path = $this->path !== '/' ? rtrim($this->path, '/') : $this->path;
$this->currentPage = $this->setCurrentPage($currentPage, $this->pageName);
$this->items = $items instanceof Collection ? $items : Collection::make($items);
}
. i currently get the error Method Illuminate\Database\Eloquent\Collection::pagination does not exist.
I want to have 3 buttons that show 3 different kinds of paginations like in stackoverflow in the search bar at the bottom.
You are calling pagination in collection try like this
first you need to include the DB class before class deceleration
use Illuminate\Support\Facades\DB;
Then change the query like this
$references = DB::table('reference')->orderBy('priority', 'desc')->orderBy('id', 'desc')->paginate(5o);
return view('admin.reference.index', ['references' => $references]);
In you view you need to access like this
{{ $references->links() }}
https://laravel.com/docs/5.7/pagination
i have currently changed the pagination completly. i wrote a url with
/x/y/perpage/10,
/x/y/perpage/30,
/x/y/perpage/100,
i made a new route for it
route::('/x/perpage/{count})'
and changed my AdminReferenceController to
public function index($perpage = false)
{
if(!$perpage) {
$perpage = 10;
}
$references = Reference::orderBy('priority', 'desc')->orderBy('id', 'desc')->paginate($perpage);
I couldn't get time to work this out. But I found you calling pagination() instead of paginate. See my suggetion
<div class="page-sizer">
<a class="page numbers" href="{{$references->paginate(10)}}">10</a>
<a class="page numbers" href="{{$references->paginate(30)}}">30</a>
<a class="page numbers" href="{{$references->paginate(100)}}">100</a>
<button href="qweqwe.qweqwe" class="btn btn-info float-right>112e1e1e1e"></button>
</div>
Here I removed the paginate from index() and returns collection.
public function index()
{
$references = Reference::orderBy('priority', 'desc')->orderBy('id', 'desc');
return view('admin.reference.index', ['references' => $references]);
}
Hope this helps you.
I have login page but i am dont know where i can take this alerts ,
i will take my script like this
echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('Your Login Succesfully ,'); window.location.href='home'; </SCRIPT>");
but i dont know how to make if else condition on my query in the model and contoller .I using num_rows but its didnt work .
my controller
public function login()
{
$u = $this->input->post('username');
$p = $this->input->post('password');
$data = $this->app_model->getlogindata($u,$p);
return $data;
}
my model
public function getlogindata($username,$password)
{
$u = $username;
$p = md5($password);
$cek_login = $this->db->get_where('login', array('username' => $u,'password'=>$p));
if(count($cek_login->result())>0)
{
foreach ($cek_login->result() as $qck)
{
if($qck->level=='puskesmas')
{
// $ambil_data = $this->db->get_where('puskesmas',array('id_puskesmas' => $u));
$this->db->select('*');
$this->db->from('puskesmas');
$this->db->join('login', 'puskesmas.id_puskesmas=login.id_puskesmas');
$this->db->where('username', $u);
$ambil_data = $this->db->get();
foreach ($ambil_data->result() as $qad)
{
$sess_data['logged_in'] = 'yes';
$sess_data['id_puskesmas'] = $qad->id_puskesmas; //
$sess_data['nama_puskesmas'] = $qad->nama_puskesmas;
$sess_data['alamat_puskesmas'] = $qad->alamat_puskesmas;
$sess_data['nama_petugas'] = $qad->nama_petugas;
$sess_data['nomor'] = $qad->nomor;
$sess_data['email'] = $qad->email;
$sess_data['level'] = $qad->level;
$this->session->set_userdata($sess_data);
}
header('location:'.base_url().'puskesmas');
} //xammp mu aktif?
elseif($qck->level=='dinas')
{
//$ambil_data = $this->db->get_where('dinas',array('id_dinas' => $u));
$this->db->select('*');
$this->db->from('dinas');
$this->db->join('login', 'dinas.id_dinas=login.id_dinas');
$this->db->where('username', $u);
$ambil_data = $this->db->get();
foreach ($ambil_data->result() as $qad)
{
$sess_data['logged_in'] = 'yes';
$sess_data['id_dinas'] = $qad->id_dinas;
$sess_data['nama_dinas'] = $qad->nama_dinas;
$sess_data['alamat_dinas'] = $qad->alamat_dinas;
$sess_data['kode_pos'] = $qad->kode_pos;
$sess_data['level'] = $qad->level;
$this->session->set_userdata($sess_data);
}
header('location:'.base_url().'dinas');
}
elseif($qck->level=='admin')
{
//$ambil_data = $this->db->get_where('admin',array('id_admin' => $u));
$this->db->select('*');
$this->db->from('admin');
$this->db->join('login', 'admin.id_admin=login.id_admin');
$this->db->where('username', $u);
$ambil_data = $this->db->get();
foreach ($ambil_data->result() as $qad)
{
$sess_data['logged_in'] = 'yes';
$sess_data['id_admin'] = $qad->id_admin;
$sess_data['nama_admin'] = $qad->nama_admin;
$sess_data['alamat_admin'] = $qad->alamat_admin;
$sess_data['status'] = $qad->status;
$sess_data['level'] = $qad->level;
$this->session->set_userdata($sess_data);
}
header('location:'.base_url().'admin');
}
else{
echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('Record Updated Successfully'); window.location.href='web'; </SCRIPT>");// i add this and still didnt work
}
}
}
}
in this script i just didnt know where i can take this alerts and what a parameter can i use to add this alerts . like if num_rows = 1 , echo = blablabla
thanks you sir
you have to use flash data in code igniter or you can use ajax callback in success you can alert what you want and redirect to whatever you like.
Controller
$this->session->set_flashdata('error_message', 'Incorrect Username or Password ! Please try again.');
redirect(URL.'backend/login');
View
<?php
if ($this->session->flashdata('error_message'))
{
?>
<div class="alert alert-danger" style="color: #fff;">
<!-- <button class="close" data-close="alert"></button> -->
<span><?php echo $this->session->flashdata('error_message'); ?></span>
</div>
<?php
}
if ($this->session->flashdata('ok_message'))
{
?>
<div class="alert alert-success">
<!-- <button class="close" data-close="alert"></button> -->
<span><?php echo $this->session->flashdata('ok_message'); ?></span>
</div>
<?php
}
?>
try this.i hope it will help you.
else{
echo '<script language="javascript">';
echo 'alert("Record Updated Successfully")';
window.location.href = 'web';
echo '</script>';
}
I would like to have it so that users that are logged into the frontend of my Joomla site can edit their articles in a new window without any template applied as soon they press on the edit Button, so that only the editor (in this case JCE) is shown.
I found the source code in components/com_content/helpers/Icon.php, but have no idea if it's possible at all or how I have to re-code it. Any idea?
// Show checked_out icon if the article is checked out by a different user
if (property_exists($article, 'checked_out') && property_exists($article, 'checked_out_time') && $article->checked_out > 0 && $article->checked_out != $user->get('id')) {
$checkoutUser = JFactory::getUser($article->checked_out);
$button = JHtml::_('image', 'system/checked_out.png', NULL, NULL, true);
$date = JHtml::_('date', $article->checked_out_time);
$tooltip = JText::_('JLIB_HTML_CHECKED_OUT').' :: '.JText::sprintf('COM_CONTENT_CHECKED_OUT_BY', $checkoutUser->name).' <br /> '.$date;
return '<span class="hasTip" title="'.htmlspecialchars($tooltip, ENT_COMPAT, 'UTF-8').'">'.$button.'</span>';
}
$url = 'index.php?option=com_content&task=article.edit&a_id='.$article->id.'&return='.base64_encode(urlencode($uri));
$icon = $article->state ? 'edit.png' : 'edit_unpublished.png';
$text = JHtml::_('image', 'system/'.$icon, JText::_('JGLOBAL_EDIT'), NULL, true);
if ($article->state == 0) {
$overlib = JText::_('JUNPUBLISHED');
}
else {
$overlib = JText::_('JPUBLISHED');
}
$date = JHtml::_('date', $article->created);
$author = $article->created_by_alias ? $article->created_by_alias : $article->author;
$overlib .= '<br />';
$overlib .= $date;
$overlib .= '<br />';
$overlib .= JText::sprintf('COM_CONTENT_WRITTEN_BY', htmlspecialchars($author, ENT_COMPAT, 'UTF-8'));
$button = JHtml::_('link', JRoute::_($url), $text);
$output = '<span class="hasTip" title="'.JText::_('COM_CONTENT_EDIT_ITEM').' :: '.$overlib.'">'.$button.'</span>';
return $output;
You should create a template override for the view, in that you can place the link to edit adding:
&tmpl=component
to the url so that only the component part will be shown; and add the
target="_blank" to the <a href or the <form tag so it goes to a new window.
This will most likely open in a new tab, if you want a new window, build the url and pass it to the window.open call.
So I've been adding tags you add to articles in Joomla!, which works fine. But now I want to show the tags in the article list layout that is default in Joomla.
I found and made an override for the list-layout and tried to add the tags code from a single article layout to the list-layout. Underneath is the code I tried to add in the list-layout. But none of the tags are shown in the layout..
<?php
// set tags
$tags = '';
if (!empty($this->item->tags->itemTags)) {
JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');
foreach ($this->item->tags->itemTags as $i => $tag) {
if (in_array($tag->access, JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')))) {
if($i > 0) $tags .= ', ';
$tags .= ''.$this->escape($tag->title).'';
}
}
}
$args['tags'] = $tags;
?>
If this isn't clear, I can try to explain it a different way.
Your php works in the sense that it builds a set of "tag" links but it doesn't actually echo it out to the page. You need to add this line either at the end of your code or somewhere after, where you want to display the tags.
echo $tags;
e.g.
<?php
// set tags
$tags = '';
if (!empty($this->item->tags->itemTags)) {
JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');
foreach ($this->item->tags->itemTags as $i => $tag) {
if (in_array($tag->access, JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')))) {
if($i > 0) $tags .= ', ';
$tags .= ''.$this->escape($tag->title).'';
}
}
}
$args['tags'] = $tags;
echo $tags;
?>
I'm not sure what you're using $args for either, it could probably be removed, unless you're using somewhere else.
public function search($query, $limit) {
// output
$output = "";
// query
$this->db->select("*");
$this->db->from("products");
$this->db->like("brand", $query);
$this->db->or_like("model", $query);
$this->db->limit($limit);
$query = $this->db->get();
// zero
if ($query->num_rows() == 0) {
$output .= "No results found";
return $output;
}
// result
foreach ($query->result_array() as $row) {
// uri
$uri2 = "{$this->base_url}specifications/{$row['brand']}-{$row['model']}";
$uri2 = str_replace(" ", "-", $uri2);
// price format
$row['price'] = number_format($row['price']);
// image url
$image = "{$this->base_url}assets/images/products/{$row['category']}-{$row['brand']}-{$row['model']}/thumb.png";
$image = str_replace(" ", "-", $image);
$output .= "<ul class=\"product\">\n
<a href=\"{$uri2}\">\n
<li class=\"product-image\"><img src=\"{$image}\" height=\"108\" width=\"57\" alt=\"\"></li>\n
<li class=\"product-brand\">{$row['brand']}</li>\n
<li class=\"product-model\">{$row['model']}</li>\n
<li class=\"product-price\">{$row['price']} <span class=\"green\">pkr</span></li>\n
</a>\n
</ul>\n";
}
// return
return $output;
}
Here I do three types of queries:
1- query that contains only brand (i get results)
2- query that contains only model (i get results)
3- query that contains both (i get no results)
How to accomplish the all above three tasks?
It seems that you are performing some kind of search, so the there result that you want to get are coming from controller or view, you jst do that make there if condition like this then do it as
if ($brand_val != '' )
{ //put your where query here }
if ($model_val != '' )
{ //put your where query here }
if ($brand_val != '' && $model_val != '' )
{ //put your where query here }
hope this will give idea
use this to print the query.
echo $this->db->last_query();
and then try execute that query in your phpmyadmin