Yii Widget component cannot find it's view in server - php

I m new to YII and I have developed a yii app using Eclipse IDE and XAMPP. It perfectly working in windows platform in my local machine. But when I deployed it into server it is not working.
this is my widget controller
"/protected/components/NotificationWidget.php"
<?php
class NotificationWidget extends CWidget {public function run() {
$notifications = Notification::model()->findAllByAttributes(array('Date'=>date('Y-m-d')));;
$this->render('/protected/components/Views/notification.php', array(
'notifications'=>$notifications
));
}}?>
And this is my view
"/protected/components/View"
<li class="dropdown notifications-menu">
<!-- Menu toggle button --> <a href="#" class="dropdown-toggle"
data-toggle="dropdown"> <i class="fa fa-bell-o"></i> <span
class="label label-warning"><?php echo sizeof($notifications);?></span> </a>
<ul class="dropdown-menu">
<li class="header">You have <?php echo sizeof($notifications);?>
notifications</li>
<li>
<!-- Inner Menu: contains the notifications -->
<ul class="menu">
<?php
foreach($notifications as $notification) {
echo "<li>".
"<a href='#'>".
" <i class='fa fa-users text-aqua'></i>". $notification->Description.
"</a></li>";
}
?>
</ul></li>
<li class="footer">View all
</li>
</ul></li>
it gives following error.
NotificationWidget cannot find the view "/protected/components/Views/notification.php".
can any one help on this.

If the server is unix like check for perfect match form lowercase / Uppercasein your path
NotificationWidget cannot find the view "/protected/components/Views/notification.php".
I think should by
NotificationWidget cannot find the view "/protected/components/views/notification.php".

Related

CodeIgniter 4 Populating menu from database on View Layout

I'm new in CodeIgniter in general. I have a view layout, on which I have navigation menu bar in it. I want to populate the dropdown menu with categories I've saved in database.
Here's snippet of my layout (View\layouts\frontend.php):
<nav class="navbar navbar-expand-md sticky-top">
<div class="collapse navbar-collapse flex-column " id="navbar">
<!-- Brand bar -->
<a class="navbar-brand ml-3" href="#">
<span class="">Test Site</span>
</a>
<!-- Internal links Menu navbar -->
<ul class="navbar-nav justify-content-center w-100 px-3">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Categories
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">News</a>
<a class="dropdown-item" href="#">Event</a>
<a class="dropdown-item" href="#">Announcement</a>
</div>
</li>
</ul>
</nav>
Now, I understand that on every views that Extends that layout, I can just do query on controller and return the view with data. Here's what I've done so far and it works.
Home Controller:
use App\Models\CategoryModel;
class Home extends BaseController
{
public function index()
{
$categoryModel = new CategoryModel();
$data['categories'] = $categoryModel->orderBy('id', 'ASC')->findAll();
return view('frontend/home_page', $data);
}
}
Part of layout:
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Categories
</a>
<?php if ($categories) : ?>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<?php foreach ($categories as $category) : ?>
<a class="dropdown-item" href="#"><?php echo $category['name'] ?></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</li>
But it looks like I have to do that on all controllers' functions that renders my views that use my layout (frontend.php).
What I want to ask is, is there a possibility to just make a function/class/something to call so it's only done one time? What is the best practice in this situation?
If
$categoryModel = new CategoryModel();
$data['categories'] = $categoryModel->orderBy('id', 'ASC')->findAll();
is something that you plan on calling in multiple methods within that Controller, then yes it would be considered best practice to push that code off into something reusable.
You could ostensibly define this function in several different places, but in this case, a private Controller function is probably easiest (it must be private to prevent it being served by web requests):
private getCategories(){
$categoryModel = new CategoryModel();
$ret['categories'] = $categoryModel->orderBy('id', 'ASC')->findAll();
return $ret;
}
Any other function within that same Controller can then get that data by calling on
$this->getCategories().
If anyone faces the same problem, here is the way I manage it. Codeigniter has a nice feature view_cell(). You can create a separate class in Libraries folder (let's call it Menu with method display()) and there return a separate view with your menu. Then in your layout call <?= view_cell('\App\Libraries\Menu::display') ?>. This way there is no need to repeat the same code in many controllers.

How to create a new menu item with information from database php and sessions

Sorry if this has been asked already before, but I tried looking for the answer and couldn't find it.
I am creating a website where a user submits information on their child such as age, school, skill level, etc. when registering.
Once they have completed registering their information and child information they can sign in and go to their dashboard.
I have a menu item that is called "dancers" and the sub menu item should be the dancer/child name that was entered when they registered. another menu item that is also there is "add new dancer".
So what I am trying to do is when they register, upon signing in they should already have the dancer in the dropdown menu for "dancers". which would have been retrieved from the database.
And every time they add a new dancer a new submenu item of that dancer's name should appear.
here is my html menu code:
<div class="row subnav">
<div class="col-sm-12">
<ul>
<li class="li-spacing">Home</li>
<li class="dropdown li-spacing">
<a class="dropdown-toggle" data-toggle="dropdown">Dancers<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Name</li>
<li class="divider"><hr></li>
<li>Name</li>
<li class="divider"><hr></li>
<li>Add New</li>
</ul>
</li>
<li class="dropdown li-spacing">
<a class="dropdown-toggle" data-toggle="dropdown">Report Cards <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>View all</li>
<li class="divider"><hr></li>
<li>Add New</li>
</ul>
</li>
<li class="li-spacing">History</li>
<li class="li-spacing">Events</li>
<li class="li-spacing">Fun</li>
</ul>
</div>
</div>
I am very new to php, and really need some direction in where to start with this.
any help is much appreciated!
After much research and working on other pages on my website I have finally found a solution that worked perfect for me.
<div class="row subnav">
<div class="col-sm-12">
<ul>
<li class="li-spacing">Home</li>
<li class="dropdown li-spacing">
<a class="dropdown-toggle" data-toggle="dropdown">Dancers<b class="caret"></b></a>
<ul class="dropdown-menu">
<?php
$dancers = "SELECT `dancer_name` FROM `dancers` WHERE name = '$name'";
$dres = mysqli_query($con,$dancers);
if($res==FALSE){
die('there was an error running query [' . $con->error . ']');
}
while($data=mysqli_fetch_array($dres)){
echo '
<li>'.$data["dancer_name"].'</li>
<li class="divider"><hr></li>
';
}
?>
</ul>
</li>
</ul>

How can I set class="active" to navigation menu in codeigniter?

I just start up to be a web developer. Now I create a dynamic website for the first time. I don't know how to set class="active" to the navigation menu.
Here is my menu code:
<li>
<i class="fa fa-users fa-lg"></i> Create Patient
</li>
<?php } ?>
<li>
<i class="glyphicon glyphicon-list-alt fa-lg"> </i> List Patients
</li>
<?php if( $usertype == "Admin"){?>
<li>
<i class="fa fa-list fa-lg"> </i> List Users
</li>`
You can use $this->uri->segment();
<li>
</i> Create Patient
</li>
<?php } ?>
<li>
</i> List Patients
</li>
<?php if( $usertype == "Admin"){?>
<li>
</i> List Users
</li>
I do this on most projects. How I achieve this is like this;
<i class="glyphicon glyphicon-list-alt fa-lg"></i> List Patients
It's matching the current uri string, with the links href. If it matches, it add's an active class to the link.
Hope this helps.
I have also used site_url over base_url
Try this one. I think no need of javascript or jquery.
If you are using codeigniter then you can use URI Class.
Get the menu from url using
$this->uri->segment();
and apply to you code like below
<li>
<i class="glyphicon glyphicon-list-alt fa-lg <?php if($this->uri->segment(1)=="memu_name"){echo "active";}?>"> </i> List Patients
</li>
I have used Codeigniter URI Class $this->uri->segment();
Please look at my code:
<li class="<?=($this->uri->segment(1)==='technology')?'active':''?>">Tech</li>
Please note....
class="<?=($this->uri->segment(1)==='technology')?'active':''?>"
Also you can use URI Class $this->uri->uri_string()
Here is my active class for home page(index)
<li class="<?=($this->uri->uri_string()=== '')?'active':''?>">Home</li>
Contact Us

give link to a view in codeigniter

I am trying to give links to different pages in the menu bar. I've created views for the page and corresponding controller is created. Also code for menu bar is written separately in another view. In this view I am trying to give link. I tried giving link with base_url(), but when the page loads links after the link which I given href is not working. I tried:
<a href="<?php echo base_url();?>admember/index">
Here, admember is controller and index is my function.
My code:
header.php
<ul class="nav navbar-nav">
<li class="active">
Dashboard
</li>
<li class="menu-dropdown classic-menu-dropdown ">
<a data-hover="megamenu-dropdown" data-close-others="true" data-toggle="dropdown" href="javascript:;">
Memeber Management <i class="fa fa-angle-down"></i>
</a>
<ul class="dropdown-menu pull-left">
<li class=" dropdown-submenu">
<a href="<?php echo base_url();?>admember/index">
<i class="icon-briefcase"></i>
Add Member </a>
</li>
<li class=" dropdown-submenu">
<a href=":;">
<i class="icon-wallet"></i>
Edit Member </a>
</li>
<li class=" dropdown-submenu">
<a href=":;">
<i class="icon-bar-chart"></i>
Delete Memeber </a>
</li>
</ul>
</li>
</ul>
Controller admember.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class admember extends CI_Controller {
public function index()
{
$this->load->view('addmember');
}
}
Can anyone help me with this. I'm a newbie in codeigniter.
Don't forget to load $this->load->helper('url'); and think problem in base url in Codeginter.
Go to application->config->config.php and change base url example as http://yourbaseurl/

html navigational menu in wordpress

I am using html nav bar in wordpress
my html nav bar code
<li class="active">
<a href="http://www.siteurl.com/shop/" class="active">
<i class="icon-nav icon-home"></i>
Home
</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=172">
<i class="icon-nav icon-star"></i>
About </a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=176">
<i class="icon-nav icon-th-large"></i>
Gallery</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=174">
<i class="icon-nav icon-comments"></i>
Services</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=4">
<i class="icon-nav icon-shopping-cart"></i>
Shop</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=187">
<i class="icon-nav icon-pencil"></i>
Blog</a></li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=145">
<i class="icon-nav icon-plus-sign"></i>
Events</a></li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=178">
<i class="icon-nav icon-map-marker"></i>
Contact</a>
</li>
</ul>
</nav>
I have tried to create a conditional tags for each page like below
example for home
<?php if ( is_home() ) { ?>
<li class="active">
<a href="http://www.siteurl.com/shop/" class="active">
<i class="icon-nav icon-home"></i>
Home
</a>
</li>
<?php } else { ?>
<li>
<a href="http://www.siteurl.com/shop/" >
<i class="icon-nav icon-home"></i>
Home
</a>
</li>
But this is not working
how to active the menu icons when we view the respective pages
If i use direct html navigational menu
Only way to do this is by using the wordpress navigation system
http://codex.wordpress.org/Function_Reference/wp_nav_menu
A lot of work has gone into their system, so there's no reason why you would want to replicate it.
Appart from reading the Codex (essential), you can search for tutorials, articles and Q&A's, there are plenty of them.
WordPress Wp_Nav_Menu with Icons and Active Item Highlight
We will be doing:
Home link in our wp_nav_menu that always gets current blog url
Customize each menu item as you want
Put pretty icons in our menu
Active item highlight
Function Examination: wp_nav_menu
In this tutorial, we’ll dive deep into everything that the
wp_nav_menu function can do, use the Walker Class to add a sub
description, and touch on some of its related functions.

Categories