I'm logging into my system and once I login, the idea is that the menu is updated according to the type of user profile, for which I'm doing from the database and showing the menu through a Foreach. However within the Foreach, when comparing one of the rows with a number, that is, with an id I get this error message and other similar ones:
Message: Undefined property: mysqli::$id_man
So I think that I'm not recognizing the value of the row, why is it happening, how could I correct it?
Controller
public function ingresar(){
$nombre_usu= $this->input->post('nombre_usu');
$pass_usu= $this->input->post('pass_usu');
$res= $this->M_Login->ingresar($nombre_usu,$pass_usu);
if ($res ==1) {
$this->load->view('layouts/Header.php');
// if the user exists, show the menu according to his profile
$data['menu_barra'] = $this->M_Login->show_menu();
$this->load->view('layouts/Menu.php', $data);
$this->load->view('usuarios/V_Index.php');
$this->load->view('layouts/Footer.php');
} else {
$data['mensaje'] = "Usuario o contraseña Incorrecta";
$this->load->view('V_Login',$data);
}
}
Model
public function show_menu(){
$id_tip= $this->session->userdata('tipo');
$this->db->select('id_mc, id_tip, id_man');
$this->db->from('mantenedores_cuenta');
$this->db->where('id_tip',$id_tip);
$menu = $this->db->get();
$horarios ="";
$informes="";
foreach ($menu as $row) {
if ($row->id_man == 1 ) {
$horarios .='<li class="active"><i class="fa fa-circle-o"></i>Administrar Horarios</li>';
}
if ($row->id_man == 2 ) {
$horarios .='<li><i class="fa fa-circle-o"></i>Agendar Citas</li>';
}
if ($row->id_man == 3 ) {
$horarios .='<li><i class="fa fa-circle-o"></i>Consultar Citas</li>';
}
if ($row->id_man == 4 ) {
$informes .='<li class="active"><i class="fa fa-circle-o"></i>Porcentaje de Citas</li>';
}
} //Fin del Foreach
$menu_barra="
<ul class='sidebar-menu'>
<li class='header'>MENU</li>
<li class='active treeview'>
<a href='#'>
<i class='fa fa-fw fa-calendar'></i> <span>Horarios</span>
<span class='pull-right-container'>
<i class='fa fa-angle-left pull-right'></i>
</span>
</a>
<ul class='treeview-menu'>
'$horarios'
</ul>
</li>
<li class='treeview'>
<a href='#'>
<span class='glyphicon glyphicon-stats'></span><span>Informes</span> <i class='fa fa-angle-left pull-right'></i>
</a>
<ul class='treeview-menu'>
'$informes'
</ul>
</li>
<li><a href='documentation/index.html'><i class='fa fa-book'></i> <span>Documentación</span></a></li>
<li><a href='documentation/index.html'><i class='fa fa-fw fa-sign-out'></i><span>Salir</span></a></li>
</ul> ";
return ($menu_barra);
}
View (menu)
<aside class="main-sidebar">
<section class="sidebar">
<div class="user-panel">
<div class="pull-left image">
<img src="<?php echo base_url();?>assets/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
</div>
<div class="pull-left info">
<p><?php echo $this->session->userdata('s_usuario');?></p>
<i class="fa fa-circle text-success"></i><?php echo $this->session->userdata('cuenta');?>
</div>
</div>
// show the menu according to your profile
<?php echo $menu_barra; ?>
</section>
<!-- /.sidebar -->
I also tried to show it in this way, but I was not allowed in an array or at least that was what the message said, example: $row["id_man"] == 3
Change
foreach ($menu as $row) {
to
foreach ($menu->result() as $row) {
See here for documentation
You could also use
foreach ($menu->result_array() as $row) {
and access properties like
$row['id_man'];
Ensure that your table mantenedores_cuenta has the following column: id_man
Related
The Image above is what I want to achieve, the only problem is am echoing subjects and topics where the topics go under the subjects, but I want to only echo say English and all topics under English will go under English. But what I have is every topic comes with its own Subjects. Thus from the Image Two English Language dropdowns.
Here is the code.
<?php
$sql = "SELECT note_id, class, subject, topic, content, author FROM notes WHERE class = 'JHS 2'";
$result = $pdo->query($sql);
$result->setFetchMode(PDO::FETCH_ASSOC);
while($row=$result->fetch()){
if(!in_array('subject', $row['subject']){
?>
<li><a class="collapsible-header waves-effect arrow-r"><i class="fa fa-chevron-right"></i><?php echo $row['subject']?><i class="fa fa-angle-down rotate-icon"></i></a>
<div class="collapsible-body">
<ul class="list-unstyled">
<li><a data-id="<?php echo $row['note_id']?>" href="<?php echo $row['note_id']?>" class="waves-effect" id="getUser"><?php echo $row['topic']?></a>
</li>
</ul>
</div>
</li>
<?php
} else {
echo ""
}
}
?>
This should output the subjects and topics and allows for multiple subjects per topic. Also, the echo "" in the else is un-needed.
<?php
$sql = "SELECT note_id, class, subject, topic, content, author FROM notes WHERE class = 'JHS 2' ORDER BY subject, topic";
$result = $pdo->query($sql);
$result->setFetchMode(PDO::FETCH_ASSOC);
$lastSubject = '';
while($row=$result->fetch()){
if(!in_array('subject', $row['subject']) {
if($lastSubject != $row['subject']) {
?>
<li><a class="collapsible-header waves-effect arrow-r"><i class="fa fa-chevron-right"></i><?php echo $row['subject']?><i class="fa fa-angle-down rotate-icon"></i></a>
<div class="collapsible-body">
<?php
}
?>
<ul class="list-unstyled">
<li><a data-id="<?php echo $row['note_id']?>" href="<?php echo $row['note_id']?>" class="waves-effect" id="getUser"><?php echo $row['topic']?></a>
</li>
</ul>
<?php
if($lastSubject != $row['subject']) {
?>
</div>
<?php
$lastSubject = $row['subject'];
}
?>
</li>
<?php
}
}
?>
I have a php/mysql driven menu. I am trying to add an active class to the menu item whenever the URI reflects that menu item (basically, when I am on that page) but every example I find is with a menu that is not populated through an array or repeater like mine.
How can manipulate the active class you see below so that it shows only when I am on that page?
Here is my menu
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if($row['id'] == 2){
// below is the active class that is now being populated accross all items equally
echo '<li class="nav-item dropdown active">';
echo '<a href="#" class="nav-link dropdown-toggle animated fadeIn animation-delay-7" data-toggle="dropdown" data-hover="dropdown" role="button" aria-haspopup="true" aria-expanded="false" data-name="services">';
echo $row["pagename"];
echo '<i class="zmdi zmdi-chevron-down"></i>';
echo '</a>';
// create a new list
echo '<ul class="dropdown-menu">';
// loop second/submenu query results
while($sub_row = $result2->fetch_assoc()) {
echo '<li>';
echo '' . $sub_row["pagename"] . '';
echo '</li>';
}
echo "</ul>";
echo '</li>';
} else { // for all other menu links
echo '<li class="nav-item dropdown active">';
echo '' . $row["pagename"] . '';
echo '</li>';
}
}
} else {
echo "0 results";
}
?>
The screenshot below shows the result after it renders. Notice the active class highlighted in yellow, it is added to every item in my main menu (the way I have it coded, which it's wrong of course). The green is the $sub_row["link"] (to answer Mark's question below
Notice, the active class is only needed to be added programmatically on the main menu. (the else portion of my code).
The screenshot below shows how the active class affects the menu item if the user was in the www.domain.com/how-it-works.php page. The active class contians the styles to make the menu item appear that way.
Thanks in advance
Hard to test with not having the DB outputs to match against mate but try this, basically you want an if statement to get the current page URL and match it against the url you get back from the DB.
<?php
if ($result->num_rows > 0) {
$pageURL = str_replace('/', '', $_SERVER['REQUEST_URI']);
$homeURL = $_SERVER['REQUEST_URI'];
// output data of each row
while($row = $result->fetch_assoc()) {
if($row['id'] == 2){ ?>
<li class="nav-item dropdown">
<a href="" class="nav-link dropdown-toggle animated fadeIn animation-delay-7" data-toggle="dropdown" data-hover="dropdown" role="button" aria-haspopup="true" aria-expanded="false" data-name="services">
<?php echo $row["pagename"];?>
<i class="zmdi zmdi-chevron-down"></i>
</a>
<ul class="dropdown-menu">
<?php while($sub_row = $result2->fetch_assoc()) {?>
<li>
<a href="<?php echo $sub_row["link"]; ?>" class="dropdown-item">
<?php echo $sub_row["pagename"] ?>
</a>
</li>
<?php } ?>
</ul>
</li>
<?php
} else if($row['id'] == 1){ ?>
<li class="nav-item dropdown <?php echo ($homeURL == $row["link"])? 'active' : '';?>">
<a href="<?php echo $row["link"]; ?>" class="nav-link dropdown-toggle animated fadeIn animation-delay-7">
<?php echo $row["pagename"]; ?>
</a>
</li>
<?php
} else { ?>
<li class="nav-item dropdown <?php echo ($pageURL == $row["link"])? 'active' : '';?>">
<a href="<?php echo $row["link"]; ?>" class="nav-link dropdown-toggle animated fadeIn animation-delay-7">
<?php echo $row["pagename"]; ?>
</a>
</li>
<?php }
}
} else {
echo "0 results";
}
?>
Edit:
Bit that gets the current page url is:
$pageURL = end(explode('/', $_SERVER['REQUEST_URI']));
Bit that does the check is (this is just a shorthand if statement:
<?php echo ($pageURL == $row["link"])? 'active' : '';?>
I have two tables Standards and Topics, Standard contain id, user_id, name and Topics contain id, user_id, name, school_id.
I want to retrive data from Standards and Topics with user login condition. So the user can only see them school name.
Error: The error is, it will be displaying school name belongs to all user not just user who log on.
I want to display school name user who log on.
this is my controller:
public function admin_subject_list($standard_id = null)
{
$this->loadModel('Subject');
$this->Subject->bindModel(array(
'belongsTo'=>array(
'Standard'
),
'hasMany'=>array(
'Topic'
)
),false);
$standard_data = $this->Standard->find('first',array('conditions'=>array('Standard.id'=>$standard_id)));
$filters = array('Topic.id'=>$this->Auth->user('id'));
$filter = array('Subject.standard_id'=>$standard_id);
$data = $this->Subject->find('all',array('conditions'=>$filter));
$this->set(compact('data','standard_id','standard_data'));
$this->set('title_for_layout', __('Standards', true));
}
this is my view file standartd_list.ctp
<?php
}
// pr($data);
$color = array('bg-kypta','bg-green','bg-aqua','bg-uni-n','bg-light-blue','bg-orange','bg-ferozi','bg-light-bluen','bg-light-yellow','bg-teal','bg-maroon');
foreach($data as $key=>$value)
{
$random = rand(0,10);
$get_subscribe_subject = $this->General->getSubscribeTutor($value['Subject']['id']);
if(empty($get_subscribe_subject))
{
?>
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box <?php echo $color[$random]?>">
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
<a style="width:33.33%;float:left;" class="small-box-footer" href="<?php echo Router::url(array('controller'=>'subjects','action'=>'view',$value['Subject']['id']))?>">
<i class="fa fa-arrow-circle-right"></i> Preview
</a>
<a style="width:33.33%;float:left;" class="small-box-footer" href="<?php echo Router::url(array('controller'=>'subjects','action'=>'edit',$value['Subject']['id']))?>"><i class="fa fa-cog" aria-hidden="true"></i> Setting
</a>
<a style="width:33.33%;float:left;" data-tab="yes" data-rel="<?php echo $value['Subject']['id'];?>" class="small-box-footer delete_subject_class" href="javascript:void(0)"><i class="fa fa-trash-o" aria-hidden="true"></i> Delete
</a>
</div>
</div>
<?php
}
else
{
// pr($get_subscribe_subject);die;
foreach($get_subscribe_subject as $k=>$v)
{
$random = rand(0,10);
?>
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box <?php echo $color[$random]?>">
<div class="inner">
<h3>
<?php
if($v['SubjectTutor']['status'] == 1)
{
$is_approved = 'yes';
}
else
{
$is_approved = 'no';
}
//goToTopicList
?>
<a data-subject_tutor_id="<?php echo $v['SubjectTutor']['id'];?>" data-is_approved="<?php echo $is_approved;?>" style="color:#fff;" class="small-box-footer" href="<?php echo Router::url(array('controller'=>'subjects','action'=>'topic_list',$v['SubjectTutor']['id']))?>">
<?php echo $value['Subject']['name']?> <?php echo $v['School']['name']?> <br>by <?php echo $v['Tutor']['first_name']." ".$v['Tutor']['last_name'] ?>
</a>
<br>
</h3>
<p>
<?php
$get_subject_topic_count = $this->General->getSubjectTutorTopicCount($v['Tutor']['id'],$value['Subject']['id'],$v['SubjectTutor']['province_id'],$v['SubjectTutor']['city_id'],$v['SubjectTutor']['school_id'],$v['SubjectTutor']['state_private']);
echo count($get_subject_topic_count);
?>
Topic(s)</p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
<a style="width:33.33%;float:left;" class="small-box-footer" href="<?php echo Router::url(array('controller'=>'subjects','action'=>'view_tutor_subject',$v['SubjectTutor']['id']))?>">
<i class="fa fa-arrow-circle-right"></i> Preview
</a>
<!--
<a style="width:33.33%;float:left;" class="small-box-footer" href="<?php echo Router::url(array('controller'=>'subjects','action'=>'edit',$value['Subject']['id']))?>"><i class="fa fa-cog" aria-hidden="true"></i> Setting
</a>-->
<?php
$check_student_subscribe = $this->General->getSubscribeInfo($v['Tutor']['id'],$value['Subject']['id']);
if(empty($check_student_subscribe))
{
$is_deletable = 'yes';
}
else
{
$is_deletable = 'no';
}
?>
<a style="width:33.33%;float:left;" data-tab="<?php echo $is_deletable?>", data-subject_tutor_id="<?php echo $v['SubjectTutor']['id'];?>" class="small-box-footer delete_item_class" href="javascript:void(0)"><i class="fa fa-trash-o" aria-hidden="true"></i> Delete</a>
</div>
</div>
<?php
}
}
}
?>
You were checking the logged in user's id with Topic's id. So, in your case you need to check the logged in user's id with the Topic's user_id.
public function admin_subject_list($standard_id = null)
{
$this->loadModel('Subject');
$this->Subject->bindModel(array(
'belongsTo'=>array(
'Standard'
),
'hasMany'=>array(
'Topic'
)
),false);
$standard_data = $this->Standard->find('first',array('conditions'=>array('Standard.id'=>$standard_id)));
$this->Subject->Behaviors->load('Containable');
$userId = $this->Auth->user('id');
$filters = array('Subject.standard_id'=>$standard_id);
$data = $this->Subject->find('all',array('conditions'=>$filters, 'contain' => array('Standard', 'Topic' => array('conditions' => array('Topic.user_id' => $userId)))));
$this->set(compact('data','standard_id','standard_data'));
$this->set('title_for_layout', __('Standards', true));
}
It looks like you're using CakePHP 2.x, right? It's also a bit unclear what you're asking, but I believe you should be able to just use standard find()s.
I want to display school name user who log on.
$topics = $this->Topic->find('all', [
'conditions' => [
'user_id' => $this->Auth->user('id')
]
]);
$standards = $this->Standard->find('all', [
'conditions' => [
'user_id' => $this->Auth->user('id')
]
]);
This will find all topics that are associated w/ the logged in user, and all standards that are associated with the logged in user.
Or, you could even simplify it by using the dynamic finders available in Cake:
$topics = $this->Topic->findByUserId($this->Auth->user('id'));
$standards = $this->Standard->findByUserId($this->Auth->user('id'));
Hi' I'm trying to get value with jquery with no success.
This part of the code I get with ajax and it's changes (it's part of a loop in function.php)
if ($termschildren) {
echo '<ul class="BlaBla">';
foreach ( $termschildren as $termchildren ) {
echo '<li class="BlaBlaLi">';
echo '' . $c_term_name->name . '';
echo '</li>';
echo '</ul>';
} else {
echo ' ';
}
die();
the ajax is return to a div called 'childrens_world'
echo '<div class="childrens_world">';
echo ' '; //for start
echo '</div>';
this is the jquery I use. I can't get the data-filter value. (the loop is fine, in the source code i see it well)
$filterLinksChildren = $('.tax-filter-children');
$('.childrens_world').on("click", $filterLinksChildren, function(e) {
var filt = $filterLinksChildren.data('filter');
//do something;
)};
I use the data-filter (var filt) to send to isotope jquery function
Thanks for any help
A couple of minor fixes:
Make the following as a string variable as opposed to a jQuery selector.
From:
$filterLinksChildren = $('.tax-filter-children');
To
filterLinksChildren = '.tax-filter-children';
There's apparently a small typographical error towards the end of the function:
)}; should actually be });
So, your complete solution would be something like the following:
filterLinksChildren = ".tax-filter-children";
$('.childrens_world').on("click", filterLinksChildren, function(e) {
alert($(this).data("filter"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="childrens_world">
<ul class="BlaBla">
<li class="BlaBlaLi">
<a href="#" class="tax-filter-children" data-filter="a1">a1
</a>
</li>
<li class="BlaBlaLi">
<a href="#" class="tax-filter-children" data-filter="a2">a2
</a>
</li>
<li class="BlaBlaLi">
<a href="#" class="tax-filter-children" data-filter="a3">a3
</a>
</li>
</ul>
</div>
<hr>
<div class="childrens_world">
<ul class="BlaBla">
<li class="BlaBlaLi">
<a href="#" class="tax-filter-children" data-filter="b1">b1
</a>
</li>
<li class="BlaBlaLi">
<a href="#" class="tax-filter-children" data-filter="b2">b2
</a>
</li>
<li class="BlaBlaLi">
<a href="#" class="tax-filter-children" data-filter="b3">b3
</a>
</li>
</ul>
</div>
You can try an alternate to get data value. Use attr
var filt = $filterLinksChildren.attr('data-filter');
this is my model:
function Countosweb(){
$sql="SELECT count(*) FROM `os` WHERE `status`='PENDIENTE ASIGNAR TÉCNICO'";
return $this->db->query($sql)->row();
}
this is my controller:
public function indexp() {
if((!$this->session->userdata('session_id')) || (!$this->session->userdata('logado'))){
redirect('mapos/login');
}
$this->data['ordensW'] = $this->mapos_model->getOsWeb();
$this->data['osn']= $this->mapos_model->Countosweb($sql);
$this->data['ordens'] = $this->mapos_model->getOsAbertas();
$this->data['produtos'] = $this->mapos_model->getProdutosMinimo();
$this->data['os'] = $this->mapos_model->getOsEstatisticas();
$this->data['estatisticas_financeiro'] = $this->mapos_model->getEstatisticasFinanceiro();
$this->data['menuPainel'] = 'Painel';
$this->data['view'] = 'mapos/panel';
//$this->session->set_flashdata('success','mensaje de prueba');
$this->load->view('tema/alte',$this->data);
}
and this is my view:
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<?php
if($osn != null){echo '<span class="label label-warning">'.$osn.'</span>';} // this is the line which is occasinating the problem.
?>
</a>
so i got this error:
A PHP ERROR WAS ENCOUNTERED
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename:tema/alte.php
line Number: 67
Please help to find the problem
PD: excuse me, my english is not very good
you shouldn't use echo to print Object - the return value in ordinary case is object or arrayuse :
print_r($osn) ;
to see the output then loop through it or use object [$object_name->item]
I advice you change your function to this as to get the number of rows returned.
function Countosweb(){
$sql="SELECT * FROM `os` WHERE `status`='PENDIENTE ASIGNAR TÉCNICO'";
return $this->db->query($sql)->num_rows();
}
Then your html should look like this.
<a href="#"
class="dropdown-toggle"
data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<?php
if(isset($osn)){
echo '<span class="label label-warning">'.$osn.'</span>';
} // this is the line which is occasinating the problem.
?>
</a>
thanks all for helping me, i solved it:
i changed this:
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<?php
if($osn != null){echo '<span class="label label-warning">'.$osn.'</span>';} // this is the line which is occasinating the problem.
?>
</a>
For this:
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<?php
if($osn != null){
foreach($osn as $on){echo'<span class="label label-warning">'.$on.'</span>';}
}
?>
</a>