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.
Related
I call the index() method of the collaborating controller, it automatically inserts 6 records into the database, and the action of logging into the database is not in the cadastrarquestao() method of the class, and not in the index method . I'm using a template library.
Controller Colaborador:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Colaborador extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('funcoes_helper');
$this->load->helper('file');
$this->load->helper('cookie');
$this->load->library('session');
$this->load->library('controle_acesso');
$this->load->model('resumoapp_model', 'resumo');
$this->load->model('homeapp_model', 'homeapp');
$this->load->model('simulado_model', 'simulado');
$this->controle_acesso->acesso();
$this->output->enable_profiler(TRUE);
}
public function index() {
$dados['teste'] = 1;
$this->template->load("template/template_app",'app/enviar-questao', $dados);
}
public function logout() {
session_unset();
redirect ('/entrar');
}
public function cadastrarquestao() {
$this->simulado->envioquestao(1);
$dados['mensagem'] = "dados cadastrados com sucesso!";
$this->template->load("template/template_app",'app/enviar-questao', $dados);
}
public function materia() {
}
}
part of the code
public function envioquestao($dados) {
$data = [
'Id_usuario' => $this->session->userdata('id_usuario'),
];
$this->db->insert('teste',$data);
}
librarie Template:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Template {
var $template_data = array();
function set($name, $value)
{
$this->template_data[$name] = $value;
}
function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
return $this->CI->load->view($template, $this->template_data, $return);
}
}
View template:
<html lang="pt-br">
<?php
$this->load->view('app/header');
?>
<body>
<div class="wrapper">
<?php
$this->load->view('app/topo');
?>
<?php
$this->load->view('app/menu');
?>
<?php echo $contents ?>
<footer class="footer-container"><span>© </span></footer>
</div>
<?php
$this->load->view('app/footer');
?>
</body>
</html>
the correct one would be to insert it in the database after clicking on 'register' which is in the cadastrarquestao() method
I'am trying call custom library function witch should return inputed values back to form, but I'am geting error.
enter image description here
Controler:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Guest extends CI_Controller {
public function __construct(){
parent::__construct();
error_reporting(E_ALL ^ (E_NOTICE));
$this->load->helper(array('form', 'url', 'date'));
$this->load->library('form_validation', 'uri');
$this->load->model('dayData');
$this->load->library('session');
$this->load->library('guest');
}
public function index(){
$this->login();
}
public function dataToView($data, $viewFile){
$this->load->view('template/header');
if($viewFile != ''){
$this->load->view('user/' . $viewFile, $data);
}
$this->load->view('template/footer');
}
public function login(){
$this->dataToView($data, 'guest/login');
}
public function registration(){
if($this->input->post('registrationSubmit') !== null) {
//$this->form_validation->set_error_delimiters('<div class="alert alert-warning" role="alert">', '</div>');
$this->config->load('form_validation');
$this->form_validation->set_rules($this->config->item('registrationValidation'));
if($this->form_validation->run() == FALSE){
var_dump($this->guest->registrationPost());
$this->dataToView($data, 'guest/registration');
} else {
echo "string";
}
} else {
$this->dataToView($data, 'guest/registration');
}
}
}
Library:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Guest {
protected $CI;
public function __construct(){
// Assign the CodeIgniter super-object
$this->CI =& get_instance();
//$this->CI->load->model('Guest');
$this->CI->lang->load('error', 'english');
}
public function registrationPost(){
$result = array('name' => $this->CI->input->post('name'),
'nickName' => $this->CI->input->post('nickName'),
'email' => $this->CI->input->post('email'));
return $result;
}
}
There is a naming conflict between the controller and the custom class. They should not have the same name.
You have duplicate class names. The controller class name is Guest and the library class name is also Guest.
When CodeIgniter goes to load the Guest library, it will skip over it and log a debug message. https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Loader.php#L1032
I suggest renaming your library to something else, Registration perhaps?
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);
I'm getting an error Undefined variable: query. I've been searching through the codeigniter forums and here for a solution but nothing seemed to work. If you can find what I'm doing wrong here I would greatly appreciate it.
Message: Undefined variable: query
Filename: views/display.php
Line Number: 3
Controller
function index() {
$this->load->model('mdl_tasks');
$data['query'] = $this->mdl_tasks->get('priority');
$this->load->view('display');
}
}
Model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mdl_tasks extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get($order_by) {
$this->db->order_by($order_by);
$query = $this->db->get('tasks');
return $query;
}
}
View
<h1>Your tasks</h1>
<?php
foreach ($query->result() as $row) {
echo "<h2>".$row->title."</h2";
}
?>
you need to include $data here:
$this->load->view('display', $data);
I am getting this error in my view file. Here is my code please do help me out and tell what to do?
<?php
//foreach($records->result() as $row):
foreach(result() as $row):
echo $row->title;
endforeach;
?>
Here is my controller file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hello extends CI_Controller
{
public function index()
{
$this->load->model('hello_model');
$data['records']=$this->hello_model->getAll();
$this->load->view('you_view',$data);
//$this->load->view('you_view');
}
}
?>
I am posting here my model file also. Ihv tried some by me, but still getiing this error. Dnt knw wt to do.
<?php
class Hello_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function getAll()
{
$q=$this->db->get('test'); // query where 'test' is table name.
if($q->num_rows()>0)
{
foreach ($q->result() as $row)
{
$data[]=$row;
}
return $data;
}
}
}
?>
$records already holds your data so this should work:
foreach($records as $row){
echo $row->title;
}
You do not need to use result() in your view,because in your model you already did.
Just try this:
<?php
foreach($records as $row):
echo $row->title;
endforeach;
?>