I want to activate and deactivate a category status from the admin side if user is active, then show that category in front side.
How can I activate and deactivate categories?
I want a button to click active and deactivate categories from the admin side.
Controller Code:-
function update_status(){
if(isset($_REQUEST['svalue']))
{
$this->load->model('categorymodel','category');
$set_status=$this->category->update_status();
if($set_status>0){
$this->session->set_flashdata('message',"category has been updated.");
}else{
$this->session->set_flashdata('message',"category has not been updated.");
}
}
return redirect("admin/category");
}
Model Code:-
function update_status(){
$sid=$_REQUEST['sid'];
$svalue=$_REQUEST['svalue'];
if ($svalue=='active') {
$status='inactive';
} else {
$status='active';
}
$data = array(
'status' => $status
);
$this->db->where('id',$sid);
return $this->db->update('category',$data);
}
View Part:-
<td>
<?php
$status = $data->status;
if ($status == 'active') {
?>
Active
<?php
} else {
?>
Inactive
<?php
}
?>
</td>
Database Table:-
Id Primary int(11)
category_name varchar(255)
slug varchar(255)
category_image text
created_at timestamp
updated_at datetime
status enum('inactive', 'active')
Currently you have following code in View.
<td>
<?php $status = $data->status;
if ($status == 'active') {?>
Active
<?php } else {?>
Inactive
<?php } ?>
<td>
You should change as below
<td>
<?php $status = $data->status;
if ($status == 'active') {?>
<a title="Click to Deactivate" href="<?php echo base_url();?>admin/category/update_status?sid=<?php echo $data->id;?>&svalue=inactive" class="btn btn success">Active</a>
<?php } else {?>
<a title="Click to Activate" href="<?php echo base_url();?>admin/category/update_status?sid=<?php echo $data->id;?>&svalue=active" class="btn btn-danger">Inactive</a>
<?php } ?>
<td>
Related
I'm trying to change the URL parameter from the row ID to the NAME of the article. here is my code
Controllers
public function view($id=0)
{
if( !isset($id) || !is_numeric($id) ) {
redirect(base_url());
}
$tot = $this->Model_service->service_check($id);
if(!$tot) {
redirect(base_url());
}
and the view is
<?php
foreach ($services as $row) {
?>
<div class="col-lg-4 col-md-6">
<div class="services-item effect-item">
<a href="<?php echo base_url(); ?>service/<?php echo $row['name']; ?>" class="image-effect">
<div class="services-photo" style="background-image: url(<?php echo base_url(); ?>public/uploads/<?php echo $row['photo']; ?>)"></div>
</a>
<div class="services-text">
<h3><?php echo $row['name']; ?></h3>
<p>
<?php echo nl2br($row['short_description']); ?>
</p>
<div class="button-bn">
<?php echo READ_MORE; ?> <i class="fa fa-chevron-circle-right"></i>
please help me with the most simplified answer thank you
Yo need to change your article view function in controller. Lookup article name instead of id. But name might contains spaces which is not URL friendly so using concept of slug will solve this.
public function view($slug='')
{
if($slug == '') {
redirect(base_url());
}
$tot = $this->Model_service->find_service_by_slug($slug);
if(!$tot) {
redirect(base_url());
}
Reference link for concept of slug is https://codeigniter.com/user_guide/tutorial/news_section.html
I have table like this
public function getDoctorPhotoRecord($count)
{
$this->db
->select('u.id, fullname, image, unvan_code, baslik, onayli')
->from('user as u')
->join('user_detail as ud', 'u.id = ud.id')
->join('tanim_sehir as us', 'ud.sehir_code = us.code')
->where('group', 'doktor')
->where('image != \'\' ')
->order_by('rand()')
->limit($count);
$query = $this->db->get();
return $query->result_array();
}
and I want this code work as
<?php
$onay = $record->detail->onayli;
?>
<?php
if ($onay == 0) {
?>
<i class="fa fa-user-md" aria-hidden="true"></i> Bu <b>Doktor</b> siz misiniz?
<?php
} else {
?>
<span class="verified" id="verifyuser" title="" data-toggle="tooltip" data-placement="bottom" data-original-title="Onaylı Üye"><i class="fa fa-check"></i></span>
<?php
}
?>
When I tried it getting data with this :
<?php echo $item['onayli'];?>
but I want active This code
<?php
$onay = $record->detail->onayli;
?>
How I can active this code ?
Thank you
The main issue is with the model, i cant figure out how to join the two tables so that i can display an item with its image which are stored in different locations.
model
$this->db->select('bs_items.id, bs_items.description, bs_items.title,
bs_items.touch_count,bs_items.price');
$this->db->from('core_images');
$this->db->join('bs_items', 'core_images.img_parent_id =
bs_items.id');
$this->db->order_by('bs_items.touch_count', 'desc');
$this->db->from('bs_items');
Controller:
this->load->model('Popular_car');
$this->load->model('Recent_car');
$data['popular_cars']= $this->Popular_car->popular_car();
$data['recent_cars']=$this->Recent_car->get_listing();
$this->load->view('templates/header');
$this->load->view('pages/home', $data);
$this->load->view('pages/home_recent', $data);
$this->load->view('templates/footer');
Please update your question with some code you have done , or database structure. i'm giving you the answer based on what i understood using your given code snippet.
Model
function get_items()
{
$this->db->select('*');
$this->db->from('core_images');
$this->db->join('bs_items', 'core_images.img_parent_id =
bs_items.id');
$this->db->order_by('bs_items.touch_count', 'desc');
$query = $this->db->get();
return $query->result();
}
Controller
function get_allitems()
{
$this->load->model('model_name');
$data['items'] = $this->model_name->get_items();
$this->load->view('view_name', $data);
}
View
<?php foreach ($items as $row): ?>
<h1><?php echo $row->title;?></h1>
<p><?php echo $row->touch_count;?></p>
<p><?php echo $row->price;?></p>
<p><?php echo $row->description;?></p>
<img src="<?php echo base_url().'path_of_image/'.$row->image_from_db; ?>
<?php endforeach; ?>
$myString = $this->db->get_where('profile_table' , array('id' => $edit ) )->row()->file_name_galery;
// $json11 = '{ "1":"s1.jpg", "2":"s2.jpg", "3":"s4.jpg", "4":"s4.jpg", "5":"s5.jpg" }';
$array = json_decode($myString);
if (empty($array)) {
echo '<p class="tx-danger"> NO IMAGE..</p>';
}
foreach($array as $key => $photo) { <div class="column_galery text-center zoom_img_app">
<a onclick="selected_photo(' echo $photo; ')" data-toggle="modal" data-target="#edit_image_mod" >
<img class="" src="http://yourapp.com/uploads/profile_gallery/ echo $photo; " style="width:100%"> <span class="tx-danger">DELETE</span> </a>
</div> }
I have edited Comment module from a tutorial to review module.
In this module i using CStarRating widget. When view, submit, delete rate post it OK. but when i click edit/update, edit old post and click update to edit rate post then star don't show, instead this radio group ???
Here is code:
CommentList.php
<?php
/** #var CArrayDataProvider $comments */
$comments = $model->getCommentDataProvider();
$comments->setPagination(false);
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$comments,
'itemView'=>'comment.views.comment._view'
));
$this->renderPartial('comment.views.comment._form', array(
'comment'=>$model->commentInstance
));
_view.php
<?php
?>
<nav id = "atext" >
<div>
<span class="ext-comment-head">
wrote on
<span class="ext-comment-date">
<?php echo Yii::app()->format->formatDateTime(
is_numeric($data->createDate) ? $data->createDate : strtotime($data->createDate)
);
?>
</span>
</span>
<span class="ext-comment-options">
<?php if (!Yii::app()->user->isGuest && (Yii::app()->user->id == $data->userId)) {
echo CHtml::ajaxLink('delete', array('/comment/comment/delete', 'id'=>$data->id), array(
'success'=>'function(){ $("#ext-comment-'.$data->id.'").remove(); }',
'type'=>'POST',
), array(
'id'=>'delete-comment-'.$data->id,
'confirm'=>'Are you sure you want to delete this item?',
));
echo " | ";
echo CHtml::ajaxLink('edit', array('/comment/comment/update', 'id'=>$data->id), array(
'replace'=>'#ext-comment-'.$data->id,
'type'=>'GET',
), array(
'id'=>'ext-comment-edit-'.$data->id,
));
} ?>
</span>
<p id = "apa">
<br>
</p>
<table id = "atable">
<td id = "test123">
<?php
$model=new Comment;
$a=$data->id;
$colArr=$model->attributes;
for ($i = 0; $i < count($colArr); $i++) {
$key=key($colArr);
$val=$colArr[$key];
next($colArr);
if (($key<> 'average') and($key<>'id') and ($key<>'message')
and ($key<>'userId') and ($key<>'createDate') ) {
$a=$a+100;
echo $data->getAttributeLabel($key).' ('.$data->$key.')';
$this->widget('CStarRating',array(
'name'=>'Comment['.$a.']',
'value'=>$data->$key,
'minRating'=>1, //minimal value
'maxRating'=>5,//max value
'starCount'=>5, //number of stars
'readOnly'=>true,
));
}
echo "<br>";
}
?>
</td>
<td id = "average-teacher">
<p>
<?php echo nl2br(CHtml::encode($data->message)); ?>
</p>
</td>
</table>
<br style="clear: both;"/>
</div>
</nav>
</div>
_form.php
<br>
<br>
<?php if (Yii::app()->user->isGuest) {
?><div class="ext-comment-not-loggedin">
Sorry, you have to login to leave a comment.
</div><?php } else { ?>
<div id="ext-comment-form-<?php echo $comment->isNewRecord ? 'new' : 'edit-'.$comment->id; ?>" class="form" >
<nav id = "comment-a">
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'ext-comment-form',
'action'=>array('/comment/comment/create'),
'enableAjaxValidation'=>false
)); ?>
<?php /** #var CActiveForm $form */
echo $form->errorSummary($comment); ?>
<div class="row">
<?php echo $form->labelEx($comment,'message'); ?>
<?php echo $form->textArea($comment,'message',array('rows'=>3, 'cols'=>76)); ?>
<?php echo $form->error($comment,'message'); ?>
</div>
<?php
$model=new Comment;
$colArr=$model->attributes;
for ($i = 0; $i < count($colArr); $i++) {
$key=key($colArr);
if (($key<> 'average') and ($key<>'id') and ($key<>'message') and ($key<>'userId')
and ($key<>'createDate') ){
$this->widget('CStarRating',array(
'name'=>'Comment['.$key.']',
'value'=>$model->$key,
'minRating'=>1, //minimal value
'maxRating'=>5,//max value
'starCount'=>5, //number of stars
));
echo " ".$model->getAttributeLabel($key)."<br>";
echo "<br>";}
next($colArr);
}
?>
<div class="row buttons">
<?php if ($comment->isNewRecord) {
echo "<br>";
echo $form->hiddenField($comment, 'type');
echo $form->hiddenField($comment, 'key');
echo CHtml::ajaxSubmitButton('Submit',
array('/comment/comment/create'),
array(
'replace'=>'#ext-comment-form-new',
'error'=>"function(){
$('#Comment_message').css('border-color', 'red');
$('#Comment_message').css('background-color', '#fcc');
}"
),
array('id'=>'ext-comment-submit' . (isset($ajaxId) ? $ajaxId : ''))
);
} else {
echo CHtml::ajaxSubmitButton('Update',
array('/comment/comment/update', 'id'=>$comment->id),
array(
'replace'=>'#ext-comment-form-edit-'.$comment->id,
'error'=>"function(){
$('#Comment_message').css('border-color', 'red');
$('#Comment_message').css('background-color', '#fcc');
}"
),
array('id'=>'ext-comment-submit' . (isset($ajaxId) ? $ajaxId : ''))
);
}
echo "<br>";
?>
</div>
<?php $this->endWidget() ?>
</nav>
</div><!-- form -->
<?php } ?>
Hope someone can help me :( And sorry about my english :(
I'm building a Joomla component and trying to use Joomla toolbars, problem is the buttons are not working properly, at least the publish and unpublish buttons are not (edit) - when I use the publish or unpublish button from the tool bar, the page reloads, it gives success message but the states remain the same.
Here's my code:
The Table File
<?php
defined( '_JEXEC' ) or die("Restricted Access");
class WetvprogramschedulerTableDay extends JTable {
public function __construct(&$db)
{
parent::__construct('#__wetv_programs_days', 'program_day_id', $db);
}
}
?>
The single record Model
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.modeladmin');
class WetvprogramschedulerModelDay extends JModelAdmin {
public function getTable($type = 'Day', $prefix = 'WetvprogramschedulerTable', $config = array()) {
return JTable::getInstance($type, $prefix, $config);
}
public function getForm($data = array(), $loadData = true) {
$form = $this->loadForm();
return $form;
}
}
?>
Edit
The List Model
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.modellist');
class WetvprogramschedulerModelDays extends JModelList {
public function __construct($config = array()) {
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'program_day',
'program_day_image',
'published'
);
}
parent::__construct($config);
}
public function getItems() {
// Run the query returned from getListQuery()
$items = parent::getItems();
// Prepare urls for View
// Doing this means we don't have to do it in the view
foreach ($items as &$item) {
$item->url = 'index.php?option=com_wetvprogramscheduler&task=day.edit&program_day_id=' . $item->program_day_id;
}
return $items;
}
public function getListQuery() {
$query = parent::getListQuery();
$query->select('*');
$query->from('#__wetv_programs_days');
// use state obtained from populateState()
$published = $this->getState('filter.published');
if ($published == '') {
$query->where('(published = 1 OR published = 0)');
} else if ($published != '*') {
$published = (int) $published;
$query->where("(published = '{$published}')");
}
$search = $this->getState('filter.search');
$db = $this->getDbo();
if (!empty($search)) {
$search = '%' . $db->getEscaped($search, true) . '%';
$field_searches =
"(program_day_image LIKE '{$search}' OR " .
"program_day LIKE '{$search}')";
$query->where($field_searches);
}
// Column ordering
$orderCol = $this->getState('list.ordering');
$orderDirn = $this->getState('list.direction');
if ($orderCol != '') {
$query->order($db->getEscaped($orderCol.' '.$orderDirn));
}
return $query;
}
protected function populateState($ordering = null, $direction = null) {
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
/*
*Check both both session and form variable to see if
*There is a value for the filter_published variable
*/
$published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published');
// If filter_published value, set it in model state.
//so we can get value when we get state.
$this->setState('filter.published', $published);
parent::populateState($ordering, $direction);
}
}
?>
The Controller
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.controlleradmin');
class WetvprogramschedulerControllerDays extends JControllerAdmin {
protected $text_prefix = 'COM_WETVPROGRAMSCHEDULER_DAYS';
public function getModel($name = 'Day', $prefix = 'WetvprogramschedulerModel', $config = array('ignore_request' => true)) {
$model = parent::getModel($name, $prefix, $config);
return $model;
}
}
?>
view.html.php
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport( 'joomla.application.component.view');
class WetvprogramschedulerViewDays extends JView {
protected $items;
protected $pagination;
public function display($tpl = null) {
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->addToolbar();
parent::display($tpl);
}
public function addToolbar() {
JToolBarHelper::title(JText::_('COM_WETVPROGRAMSCHEDULER_DAYS_TITLE'));
JToolBarHelper::addNew('day.add');
JToolBarHelper::editList('day.edit');
JToolBarHelper::divider();
JToolBarHelper::publishList('days.publish');
JToolBarHelper::unpublishList('days.unpublish');
JToolBarHelper::divider();
JToolBarHelper::archiveList('days.archive');
JToolBarHelper::trash('days.trash');
}
}
?>
default.php
<?php defined( '_JEXEC' ) or die("Restricted Access"); ?>
<form action="index.php?option=com_wetvprogramscheduler&view=days" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
<thead>
<tr>
<th width="1%">
<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
</th>
<th><?php echo JText::_('COM_WETVPROGRAMSCHEDULER_FIELD_DAY_NAME_LABEL') ?></th>
<th><?php echo JText::_('COM_WETVPROGRAMSCHEDULER_FIELD_DAY_IMAGE_LABEL') ?></th>
<th><?php echo JText::_('JSTATUS') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2 ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->progam_day_id); ?>
</td>
<td>
<a href="<?php echo $item->url; ?>">
<?php echo $this->escape($item->program_day) ?></a>
</td>
<td><?php echo $this->escape($item->program_day_image) ?></td>
<td class="center">
<?php echo JHtml::_('jgrid.published',
$item->published, $i, 'days.', true, 'cb'); ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
</table>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</form>
Here's the sql statement for the table.
CREATE TABLE IF NOT EXISTS #__wetv_programs_days (
program_day_id BIGINT(20) NOT NULL AUTO_INCREMENT,
program_day VARCHAR(9) NOT NULL,
program_day_image VARCHAR(255) NOT NULL,
program_day_access int(11) DEFAULT '1',
program_day_alias varchar(255) DEFAULT NULL,
published tinyint(1) DEFAULT '0',
checked_out int(11) DEFAULT '0',
checked_out_time datetime DEFAULT '0000-00-00 00:00:00',
program_day_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (program_day_id),
UNIQUE (program_day),
UNIQUE (program_day_alias)
);
Missing "r" from progam_day_id in default.php in the checkbox cell.
It should be program_day_id