Codeigniter is showing 404 Error in live website - codeigniter

i am trying to add a page into existing Codeigniter website. www.cryptolord.com
I have added the link in template.php file
i have made the page in view as sell.php
I have made the page in Controller as Sell.php
Still having 404 error.
Please help to solve this issue.
Thanks
defined('BASEPATH') OR exit('No direct script access allowed');
class Protect extends Public_Controller
{
function __construct()
{
parent::__construct();
$this->lang->load('welcome');
}
function index()
{
$this->set_title(sprintf(lang('core button sell'), $this->settings->site_name));
$data = $this->includes;
$content_data = array();
$data['content'] = $this->load->view('sell', $content_data, TRUE);
$this->load->view($this->template, $data);
}
}
This is for sell.php in Views
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?> <div class="header-bg">
<div class="container">
<div class="row">
<div class="col-md-9 col-sm-6 col-xs-7">
<h3><?php echo lang('core button sell'); ?></h3>
</div>
</div>
</div>

The problem is that your Sell.php controller has a class inside it that is "Protect", and it should be "Sell".
So this line:
class Protect extends Public_Controller
Should be like this:
class Sell extends Public_Controller
You must have your own base controller named "Public_Controller", but if not you should also change that to "CI_Controller".

Related

How to show validation errors in view using redirect in codeigniter?

I try different methods but it's not working.
My question is how can achieve both these requirements: passing validation data and pass my data which I get from the database
*
<?php
class Jobpost extends my_controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('html','url'));
}
function index()
{
$this->load->model('new_post','model');
$ans= $this->model->get_user_data();
$this->load->view('website/job_post',['ans'=>$ans]);
}
public function new_post()
{
if ($this->form_validation->run('post') == FALSE)
{
$this->index(); /* index function above. */
}
else
{
echo "succes";
}
}}?
<div class=" text-center">
<?php echo validation_errors(); ?>
</div>
You can pass the error messages as flashdata. This works with the session library.
It can be implemented as follows
In your controller:
$this->session->set_flashdata('Failure', 'failure message.');
redirect("To your view");
In the View
<?php if($this->session->flashdata('Failure')){ ?>
$('.confirm-div').html('<?php echo $this->session->flashdata('Failure'); ?>').show();
<?php } ?>

Codeigniter - cannot load any view at all

I have built a website with the CodeIgniter framework.
Unfortunately, I am having a problem with CodeIgniter's load->view() function.
Every time I try to load another view file with the code $this->load->view('any_view_file'); I get the error:
unable to load the requested file 'any_view_file'.php
For example i am having problems with the $this->load->view('available_lessons.php', $data); command. So let's try to recreate the problem and think this through...
I am calling the load_available_lessons() function of the Lessons.php controller
The load_available_lessons() function uses the get_lessons() function of the db_model.php model and saves the result on the $data['result'].
Then, the load_available_lessons() function calls the available_lessons view file while parsing the $data to it.
Here is where the problem rises. CodeIgniter is unable to load the view. As i explained earlier, CodeIgniter fails to load any view...!!!
Any suggestions please?
My .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\\.php|images|css|lessons|robotos\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
From my config.php file:
$config['index_page'] = '';
From my routes.php file:
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['translate_uri_dashes'] = TRUE;
My Pages.php Controller:
<?php
class Pages extends CI_Controller {
public function view($page = 'home')
{
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
else
{
$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);
}
}
}
?>
My Lessons.php Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Lessons extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('db_model');
/* $this->load->library('acl'); */
/* $this->load->helper(array('form', 'url')); */
}
public function index()
{
$this->load->view('available_lessons', array('error' => ' ' ));
}
public function load_available_lessons()
{
$data['result'] = $this->db_model->get_lessons();
$this->load->view('available_lessons.php', $data); /* available_lessons */
}
}
?>
My db_model.php Model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class db_model extends CI_Model{
public function __construct()
{
parent::__construct();
}
public function new_lesson($data)
{
/* Inserting in Table "lessons" of CodeIgniter's Database */
$this->db->insert('available_lessons', $data);
}
public function get_lessons() /* $data */
{
/* Get lessons from Table "lessons" of CodeIgniter's Database */
$this->db->select('Name, Description, DateAdded, LastEdit, UserID, FileName');
$this->db->from('lessons');
$query = $this->db->get();
return $result = $query->result();
}
}
?>
My available_lessons.php View file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div class="container">
<h6 class="description">Browse Lessons</h6>
<div class="row">
<section id="lessons-panel" class="col-xs-12 col-md-8 col-md-offset-2">
<table>
<tr>
<th>Content</th>
</tr>
<?php foreach($this->result as $r): ?>
<tr><?php echo $r->content; ?>
</tr>
<?php endforeach; ?>
</table>
</section>
</div>
</div>
As #ourmandave and a coworker pointed out to me, i should add the "pages/" before every view name that i want to call. For example, in the Lessons.php controller, i should have $this->load->view('pages/available_lessons.php', $data); As it turned out he is right.
The thing is that i cannot understand the reason why i should include the "pages/" as I have already included this in the Pages.php controller. It seems that the Pages Controller is not being used when i call a view. I will have to look into it later on.
Thank you all for your valuable input!!!!! Just another rookie mistake...

Error displayed when trying to insert data from db into dropdown list within CodeIgniter

The following error is displayed:.............................................
Severity: Notice
Message: Undefined variable: groups
Filename: views/content_view.php
Line Number: 10
please can you assist me...below is the code that i have tried
below is my controller
**MY CONTROLLER**
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Delivery_controller extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('model_get');
}
public function delivery()
{
$data['groups'] = $this->model_get->getAllGroups();
$this->load->view("site_header");
$this->load->view("site_nav");
$this->load->view('login');
$this->load->view('content_view');
$this->load->view("content_video");
$this->load->view("site_footer");
}
}
?>
below is my view
**MY VIEW**
<div id="content" class="col-md-6">
<h1> Comparison</h1>
<select class="form-control">
<?php
if (is_array($groups))
{
foreach($groups as $row)
{
echo '<option value="'.$row->page.'">'.$row->page.'</option>';
}
}
?>
</select>
</div>
below is the relevant information from the model
MY MODEL
class Model_get extends CI_Model{
public function __construct()
{
parent::__construct();
}
function getAllGroups()
{
$query = $this->db->query('SELECT page FROM pageData');
return $query->result();
}
}
Try:
$this->load->view('content_view', $data);

How to create own login form in Ion Auth for CodeIgniter?

Im trying to use Ion Auth to protect admin area on my site.
I installed Ion Auth (added tables, copied files).
I added file application/system/core/MY_Controller.php which looks like this:
<?php
class Admin_Controller extends CI_Controller {
//Class-wide variable to store user object in.
protected $the_user;
public function __construct() {
parent::__construct();
if (!$this->ion_auth->is_admin() )
{
redirect('/auth/login');
}
}
}
?>
In all my controllers in admin area I changed CI_Controller to Admin_Controller, like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Start extends Admin_Controller
{
public function index()
{
$this->load->view('layout/_header');
$this->load->view('layout/_left');
$this->load->view('admin/start');
$this->load->view('layout/_footer');
}
}
Now I'm trying to figure out how to create own login form wrapped with my layout views.
I have no idea how to do it. In 'auth/login' controller view is loaded in some weird way:
$this->_render_page('auth/login', $this->data);
Can somebody help me to write login form, which will be compatybile with my method for loading views?
I mean that method:
$this->load->view('layout/_header');
$this->load->view('layout/_left');
$this->load->view('admin/login'); // i want to load login form here
$this->load->view('layout/_footer');
I would recommend to read this: http://benedmunds.com/ion_auth/
login view:
<div id="infoMessage"><?php echo $message;?></div>
<?php echo form_open("auth/login");?>
<p>
<?php echo lang('login_identity_label', 'identity');?>
<?php echo form_input($identity);?>
</p>
<p>
<?php echo lang('login_password_label', 'password');?>
<?php echo form_input($password);?>
</p>
<p>
<?php echo lang('login_remember_label', 'remember');?>
<?php echo form_checkbox('remember', '1', FALSE, 'id="remember"');?>
</p>
<p><?php echo form_submit('submit', lang('login_submit_btn'));?></p>
<?php echo form_close();?>
<p><?php echo lang('login_forgot_password');?></p>
public function __construct() {
parent::__construct();
// Check if the user is already logged in
if (!$this->ion_auth->logged_in()) {
// If not, we send him to the login Page
redirect('admin/user/login', 'refresh');
}
}

why is this error showing

I am using CI for my web-site. While programming CMS for the same I faced no problem but when I am programming the same for user-end I am getting error as:
"404 Page Not Found
The page you requested was not found."
What am i doing wrong?? Any help/suggestions is warmly welcome.Thank you.
In Controller(model.phpl):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->load->model('common');
$this->load->model('home_model');
$this->load->model('page_model');
}
function _remap($method , $params = array())
{
$this->menu = $this->common->createMenuArr();
$this->index();
}
function index()
{
$data['sliderArr'] = $this->user_model->sliders();
$this->load->view('index', $data);
}
}
In Model(user_model.php):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model{
function __construct()
{
parent::__construct();
//$this->load->database();
}
function sliders()
{
$query = $this->db->query("SELECT slider FROM tbl_sliders ORDER BY slider_id DESC")->result_array();
return $query;
}
}
and finally in view(index.php):
<div id="slideContainer">
<div id="slideShim">
<?php
if(!empty($sliderArr))
{
foreach($sliderArr as $slider)
{ ?>
<img src="<?php echo base_url();?>images/sliders/<?php echo $slider['slider'];?>"
<?php }
}
?>
</div>
</div>
Go to Application -> Config -> Routes.
And Set $route['default_controller'] = "index"; //whatever your controller name is on which you want your application to route by default
Hope this helps.

Resources