I am new in codeIgniter..Im trying to create an anchor tag to link my home page from home page like this
main-nav.php
<li>
<?php echo anchor('Welcome/home', 'Home', 'class="icon icon-photo"') ?>
</li>
but when I click the home button its show me a blank page in staid the main page or the same page.
in my controller
here is my code
Welcome.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->home();
}
public function home() {
$this->load->model('model_books');
$this->load->helper('html');
$this->load->helper('url');
$data['books_details'] = $this->model_books->getBookDetails();
$data['title'] = 'NMSC Online Library';
$this->load->view('welcome_message', $data);
$this->load->view('templates/main_nav');
$this->load->view('templates/header');
$this->load->view('main_body');
$this->load->view('templates/footer');
}
}
what im trying to do is i have a main page that have a button that link into own page i mean the main page. ( main page link to main page ).
I knew how to link a page in pure html like this..
Home
but in codeigniter i cant. pls help.
thanks and advance..
in my controller i have a Welcome.php
the code is shown already above.
in views folder there is a folder name templates inside of it i have a main_nav.php. the code is
<body>
<div class="container">
<!-- Push Wrapper -->
<div class="mp-pusher" id="mp-pusher">
<!-- mp-menu -->
<nav id="mp-menu" class="mp-menu">
<div class="mp-level">
<h2 class="icon icon-world">All Categories</h2>
<ul>
<li>Home
</li>
<li><a class="icon icon-photo" href="#">Staff</a </li>
<li class="icon icon-arrow-left">
<a class="icon icon-news" href="#">Events & Activities</a>
<div class="mp-level">
<h2 class="icon icon-news">Events & Activities</h2>
<a class="mp-back" href="#">back</a>
<ul>
<li>Orientation Schedule</li>
</ul>
</div>
</li>
<li><a class="icon icon-photo" href="#">Services</a></li>
<li><a class="icon icon-photo" href="#">Linkages</a></li>
<li class="icon icon-arrow-left">
<a class="icon icon-news" href="#">Databases</a>
<div class="mp-level">
<h2 class="icon icon-news">Databases</h2>
<a class="mp-back" href="#">back</a>
<ul>
<li>Proquest</li>
<li>E-books Open Access</li>
<li>Journals Open Access</li>
<li>Low Online Resources</li>
<li>Medical & Nursing Resources</li>
<li>Thesis & Dissertations</li>
<li>News Online Resources</li>
<li>Other Online Resources</li>
</ul>
</div>
</li>
<li><a class="icon icon-photo" href="#">Service Hours</a></li>
<li><a class="icon icon-photo" href="#">WebLIS-OPAC</a></li>
<li><a class="icon icon-photo" href="#">Library System</a></li>
<li><a class="icon icon-photo" href="#">New Acquisitions</a></li>
<li><a class="icon icon-photo" href="#">The Librarian</a></li>
</ul>
</div>
</nav>
<!-- /mp-menu -->
<div class="scroller"><!-- this is for emulating position fixed of the nav -->
i wold link that homepage button to the same page..
in my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /nmsc-online-library/
# If your project is in server root then should be: RewriteBase /
# If project is in folder then it should be: RewriteBase /folder_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
To set Home Controller
Goto application/config/routes.php
$route['default_controller'] = "controller_name/method";
#if you define you first method inside index() then no need of entering method in second parameter.
And create link to another controller.
Home
About Us
Products
Corsair
Contact Us
If you place .htaccess file the you can remove index.php in above URL
EDIT 01
In .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
try this:
<li>
<?php echo anchor("", "Home", array("target" => "_self")); ?>
</li>
Write this in your li tag if your controller name is welcome
or if its Welcome then change it to
Related
I have the website in a subfolder _demo (laravel app)
Here is my htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^teacode.ma$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.teacode.ma$
RewriteCond %{REQUEST_URI} !_demo/public/
RewriteRule (.*) /_demo/public/$1 [L]
all the routes works except for /courses/search route which takes me to
http://example.com/_demo/public/courses/search?term=term
Here is the form (should take to http://example.com/courses/search?term=term)
<form class="form-inline my-2 my-lg-0" action="/courses/search/" method="GET">
<input class="form-control search-input" type="search" name="term" required placeholder="Search">
<button class="btn search-btn" type="submit">
<i class="fas fa-search"></i>
</button>
</form>
I solved it , the problem was in the last '/' on the /courses/search/ , I changed it to /courses/search
hi im new with codeigniter, i need to view home.php after login but no luck , there is CI error message :
An Error Was Encountered Unable to load the requested file: $content.php
fyi, there is 2 file inside home.php (v_sidebar.php , v_isi.php )
application/controller/home.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$isi['content'] ='v_isi';
$this->load->view('v_home',$isi);
}
}
application/view/v_home.php
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
<?php echo $this->load->view('$content');?>
<!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.page-content -->
and of course the file called v_isi.php exist
application/view/v_isi.php
<div class="alert alert-block alert-success">
<button type="button" class="close" data-dismiss="alert">
<i class="ace-icon fa fa-times"></i>
</button>
<i class="ace-icon fa fa-check green"></i>
Welcome to
<strong class="green">
Ace
<small>(v1.3.3)</small>
</strong>,
the lightweight, feature-rich and easy to use admin template.
</div>
but after succes with login page , the file v_isi.php couldnt load even the file exist.
need some help here...
Change :
<?php echo $this->load->view('$content');?>
to
<?php $this->load->view($content);?> // removed echo & quotes
and you're done.
I have tried many google hits but I am yet unable to retrieve any POST data from forms, $_POST is just an empty array array(0) { }. I found few posts which was saying that problem is in .htaccess which doesn't correctly redirect my POST data but any of those posts didn't help me. I have tried many .htaccess files I found but none of them worked with POST data.
I am using Debian Jessie with Apache 2.4.10, PHP 5.6.14-0+deb8u1. I have AllowOverride all inside <Directory at my VHOST file. CodeIgniter 3.0.3. I have var_dump($_POST); at top of the index.php for testing. I also have enabled rewrite_module. There are no errors in the apache2 error.log file.
Here is my setup:
Controller: Admin.php
<?php
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->library('session');
$this->load->library('form_validation');
}
public function index()
{
if(isset($this->session->userdata['logged']))
{
$this->load->view('admin/dashboard');
}
else
{
$this->load->view('templates/default/header');
$this->load->view('admin_login');
$this->load->view('templates/default/footer');
}
}
public function login()
{
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() == FALSE)
{
echo "Validation failed!";
}
else
{
echo "Validation success!";
}
}
}
View: admin_login.php:
<form class="form-signin" method="post" action="/admin/login/">
<h2 class="form-signin-heading">Kirjaudu sisään</h2>
<label for="inputEmail" class="sr-only">Sähköpostiosoite</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Sähköpostiosoite" required autofocus>
<label for="inputPassword" class="sr-only">Salasana</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Salasana" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Muista minut
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Kirjaudu</button>
Current .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Your action is wrong. It should come like this
action="<?php echo base_url()?>admin/login/">
as well as load url in helpers
$this->load->helper('form','url');
as well as in these input tags there is no name attribute
<input type="email" id="inputEmail" class="form-control" placeholder="Sähköpostiosoite" required autofocus>
<input type="password" id="inputPassword" class="form-control" placeholder="Salasana" required>
Do like this
In controller
$this->load->helper('form'); #load library
In view
<?
$attributes = array('class' => 'form-signin');
echo form_open('admin/login/', $attributes);
$data1 = array(
'id' => 'inputEmail',
'class' => 'form-control',
'Placeholder' => 'Sähköpostiosoite',
'name' => 'email',
);
echo form_input($data1);
$data2 = array(
'id' => 'inputPassword',
'class' => 'form-control',
'Placeholder' => 'Salasana',
'name' => 'password',
);
echo form_password($data2);
echo form_submit('submit', 'Log In');
echo form_close();
Try this:
In controller add $this->load->helper(array('form','url')); in function __construct()
In View:
<form class="form-signin" method="post" action="<?php echo base_url()?>admin/login">
<h2 class="form-signin-heading">Kirjaudu sisään</h2>
<label for="inputEmail" class="sr-only">Sähköpostiosoite</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Sähköpostiosoite" required autofocus>
<label for="inputPassword" class="sr-only">Salasana</label>
<input type="password" name = "password" id="inputPassword" class="form-control" placeholder="Salasana" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Muista minut
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Kirjaudu</button>
Hope this help! ^^
I have hosted a site in my live server for testing.but i have used code to get to the specific controllers in my system .It is working well in my localhost but in my live server it doesnt work
Url are as follows
In local
a localhost:55/axxxx
b 69.1xx.xxx.xxx/~username/axxxx/axxxx
when calling a controller using a it works well but when calling the controller using b it gives me 404 error
here is my co`index.php/Authenticaton/authenticate">
<p>
<label for="login">Username</label>
<input type="text" name="username" placeholder="Username or email" required>
</p>
<p>
<label for="password">Password</label>
<input type="password" name='password' placeholder="Password" required>
</p>
<p>
<input type="submit" name="submit" id="login" class="btn-1" value="Continue">
</p>
</form>`
Pleas help me in this situation
Sorry for the Bad English
Thanks in Advance
Does it work while putting index.php before controller name, if so take a look at your htaccess.This might work:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
might be base_url is pointing to different location.
Put this instead of base_url:
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
Joomla Geeks!
Please help me. Web designers created design for Joomla, where
<jdoc:include type="message" />
should be located inside of custom component's view (default.php). It's because of divs nesting, I can't change anything.
Nevertheless, I have to find a solution to include Joomla system messages in component's view (default.php) instead of template's index.php, how to do that? Is it possible?
UPD: I've solved the problem, but now I need to override this code:
<dl id="system-message">
<dt class="message">MESSAGE_TYPE</dt>
<dd class="message message fade">
<ul>
<li>MESSAGE_TEXT</li>
</ul>
</dd>
</dl>
with this one:
<div class="message">
<span class="jsMessage info_message">
<span>
MESSAGE_TEXT <a class="close jsCloseMessage" href="javascript:void(0)"></a
</span>
</span>
</div>
Should I use templates/mytemplate/html/modules.php file for that?
$document = & JFactory::getDocument();
$renderer = $document->loadRenderer('message');
$msg=$renderer->render();