I am new in codeigniter.i'm trying to linked another view, but codeigniter not showing my view.here is my view code.
<div class="logo">
<img src="<?= base_url('assets/') ?>img/kliniku.png" alt="" />
</div>
<ul class="navigasi">
<li>about</li>
<li>login</li>
</ul>
</nav>
here is my controller code 'auth.php'
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Auth extends CI_Controller
{
public function index()
{
$this->load->view('auth/login');
}
}
thank you for helping me.
if you are using Xampp check your project folder
in your htaccess file you have to set RewriteBase to your folder name
RewriteBase /YOUR_PROJECT/
check your config file in application/config/config.php
$config['base_url'] = "";
check route file in application/config/route.php
$route['default_controller'] = 'YOUR_Control_NAME';
change the link as below
login
or
login
Related
I have created a custom library in Codeigniter and initialized and running well. I am in need of help to include the CSS and JS which are needed for my custom library. I am creating my custom library as a plugin.
Folder Structure:
Application
1.1. libraries
1.1.1 custom_library_folder
CSS
JS
Custom_Library_File.php
sk_form.php
Custom_Library_File.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sdkat{
function __construct()
{}
public function sdkat_library()
{
include('sk_form.php');
}
}
?>
In the sk_form.php I am in need to include the CSS and JS Files for my designing purpose.
sk_form.php
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/libraries/sdkat/css/style.css">
<form method="post">
<div class="input">
<label>Username: </label>
<input type="text" name="username" placeholder="Enter Username">
</div>
<div class="input">
<label>Password</label>
<input type="password" name="password" placeholder="Enter Password">
</div>
<div class="input">
<input type="submit" name="login" value="Login">
</div>
</form>
The CSS is not calling and I get Access forbidden! error when I view the CSS in the Browser.
Note: I am in need to include the CSS and JS from my custom library. Could anyone help me to figure it out where I have gone wrong?
Try this method to include files on Application path
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sdkat{
function __construct()
{
$this->load->helper('url');
}
public function sdkat_library()
{
require_once(APPPATH."custom_library_folder/sk_form.php");
}
}
?>
It's because of security reasons, CI added .htaccess file inside application folder in your file system. Inside that they written like ..
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
Because of Require all denied its restricting files.
To overcome this create a .htaccess inside your "sdkat" folder and add the following line.
Require all granted
Restart server if needed
Add Codeigniter's default index.html inside "sdkat" folder and all it's sub folders to avoid directory browsing.
I am working on Laravel 5.4
I have created a menu, in which three tabs Home, about and contact. When I click on Home then it should be on home page. When click on about, it should be on about page....
web.php:
<?php
Route::get('/', function()
{
return View('method1.home');
});
Route::get('about', function()
{
return View('method1.about');
});
**method1 is folder in resources\views**
home.blade.php:
#extends('method1.dashboard')
#section('content')
<h1>This is home page</h1>
#endsection
about.blade.php is:
#extends('method1.dashboard')
#section('content')
<h1>This is about page</h1>
#endsection
dashboard.blade.php is:
#include('method1.includes.menu-header')
menu-header.blade.php is:
<li class="active"> Home</li>
<li> About</li>
But when I click on home or about page. It shows Page is not found.
My laravel projet folder name is admin_laravel. When I run http://localhost/admin_laravel/ then it shows home page and when run http://localhost/admin_laravel/about it shows about page.
But when I click on about menu button then in browser shows link http://localhost/about. Means it is not going with http://localhost/admin_laravel/about and page is not showing.
You are missing something there, For a quick fix you can do this:
<li class="active"> Home</li>
<li> About</li>
You can also give route name and go with route method:
Route::get('about', function()
{
return View('method1.about');
})->name('about');
Then:
<li> About</li>
Here is the details: https://laravel.com/docs/5.2/helpers#method-route
You're hard-coding your URLs. When you have <li>About</li> you're telling your browser to go to the about path from the root of the domain (which is what happens when you prefix your URL with /), which in this case is http://localhost/.
There's a few things you should be doing. First, set the base URL for your project, you can update APP_URL in your .env file
APP_URL=http://localhost/admin_laravel
or the url option in config/app.php.
'url' => env('APP_URL', 'http://localhost/admin_laravel'),
Secondly, when generating URLs in Laravel there are quite a few options. If you're not using named routes, then you should use the url helper method to generate your URLs:
<li>About</li>
That will make sure that your URL is based at the root of your project, rather than the root of the domain. When you use url in conjunction with the correct setting as described above, your URLs will be generated correctly.
First time i am working on CI project. I am having one linking issue.
header.php : (views)
<li class="">
<a title="" href="<?php echo site_url('index.php/welcome/index')?>">
<i class="icon icon-share-alt"></i>
<span class="text">Logout</span>
</a>
</li>
In Welcome.php : (controller)
public function index(){
$this->load->view('layouts/login');
}
From this i am getting this error:
( ! ) Warning:
include(F:\xampp\htdocs\payroll_crm\application\views\errors\html\error_php.php):
failed to open stream: No such file or directory in
F:\xampp\htdocs\payroll_crm\system\core\Exceptions.php on line 268
please help me with the same.I did not work on routing. is there need of routing?
Have you: Register/defined your route in application/config/routes.php in $route array?
You might wanna look: https://www.codeigniter.com/userguide3/general/routing.html
I am using CodeIgniter v3.1.3. Based on the 'Static Page' tutorial, I am trying to create a static website containing 5 pages such as Home, About, Services, Portfolio, and Contact.
I have a Pages.php controller inside 'application/controllers' directory.
My Pages.php controller looks like
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
//Controller logic
public function view($page = 'home')
{
if(!file_exists(APPPATH.'views/pages/'.$page.'.php')){
//Whoops!, we don't have a page for that
show_404(); //In-built CI function to show 404 error pages
}
$data['title'] = ucfirst($page); //Capitalize the first letter
$this->load->view('templates/header',$data);
$this->load->view('pages/'.$page,$data);
$this->load->view('templates/footer',$data);
}
}
I have also created the 5 static pages inside 'application/views/pages' like home.php, about.php, services.php, portfolio.php, contact.php
Common codes of header & footer exists at 'application/views/templates' like footer.php & header.php.
My navigation menu inside header.php looks like
<li><a class="curr_menu" href="<?php echo base_url('pages/view/home');?>">Home</a>
</li>
<li><a class="page-scroll" href="<?php echo base_url('pages/view/about');?>">About Us</a>
</li>
<li><a class="page-scroll" href="<?php echo base_url('pages/view/services');?>">Services</a>
</li>
<li><a class="page-scroll" href="<?php echo base_url('pages/view/portfolio');?>">Portfolio</a>
</li>
<li><a class="page-scroll" href="<?php echo base_url('pages/view/contact');?>">Contact Us</a>
</li>
My routes.php(application/config/routes.php) looks like
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
The homepage is shown initial load, however when I click on any menu items, it returns '404 Page Not Found' error.
Can someone please explain - with clear code - show to make my menu work.
.htaccess at the root contains
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I highly recommend you to manually navigate to the wanted pages by writing the URL by hand in the address bar to make sure the error comes from the link building.
If so, then try using
<?php echo site_url('pages/view/home');?>
Probably your url is coming out wrong. Your default controller is
"Pages/view " ??
If so, then the navigation menus should be like this :
<li><a class="curr_menu" href="<?=base_url()?>home">Home</a>
</li>
<li><a class="curr_menu" href="<?=base_url()?>about">About Us</a>
</li>
<li><a class="curr_menu" href="<?=base_url()?>services">Services</a>
</li>
<li><a class="curr_menu" href="<?=base_url()?>portfolio">Portfolio</a>
</li>
<li><a class="curr_menu" href="<?=base_url()?>contact">Contact Us</a>
</li>
And in the config.php file,
$config['base_url'] = 'http://yoururl/'; //should be followed by forward slash (/)
$config['index_page'] = '';
In order to use base_url() you have to load url helper first in your controller.Like this
public function __construct(){
parent::__construct();
$this->load->helper('url');
}
Or you can load it in application/config/autolaod.php.Like this...
$autoload['helper'] = array('url');
And don't forget to set bae_url at application/config/config.php
$config['base_url'] = 'your_url';
Also
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
In your root folder. .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I want to load my home page(base_url) when I click on my logo.
Base url - (http://localhost:8888/adminpanel/)
When I use base_url() function inside the anchor tag like <a href="<?php echo base_url(); ?>" , It taking me to (http://localhost:8888/adminpanel/index.html).
Actually I couldn't find this index.html anywhere in my adminpanel folder.
So friends please help me to find a solution for this. Thanks in Advance. :)
okay i got it can you please try with
<a class="navbar-brand" href="<?php echo base_url();?>blog"><img src="<?php echo base_url()?>assets/img/ro.jpg" class="img-responsive" alt="" title=""></a>
dont write your url inside the function
just try with this
If you want to go to your homepage the you can use <?php echo site_url()?>
base_url in simple words used for getting base path necessary for css or images
if your hompage is http://www.example.com you can have <?php echo site_url()?>
and if you want to go to http://www.example.com/index.php/dashboard you can have <?php echo site_url('dashboard'); ?>
where in config.php
$config['base_url'] = '';
$config['index_page'] = 'index.php';
give a try to the above things.
More description regarding site_url and base_url can be found here
what is the difference between site_url() and base_url()?
In config.php set following:
$config['base_url'] = 'http://example.com/'; // Set your Home URL
If you are using mod_rewrite than change following..
$config['index_page'] = '';