• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
View located in different default folder

#1
Question 
Hi,

I have a controller in folder APP\CONTROLLERS

And view in folder THEMES\DEFAULT\VIEW

When try to open page, get error:

404 page not found, what is the way as have to work function to call view from controller?

Regards
Reply

#2
You can find everything you are looking for in the manual.
https://www.codeigniter.com/user_guide/t...pages.html
https://www.codeigniter.com/user_guide/g...llers.html
https://www.codeigniter.com/user_guide/g...views.html

If you still have any problems, you NEED to post some code and what URL you try to access.
Reply

#3
(01-11-2018, 03:01 PM)jreklund Wrote: You can find everything you are looking for in the manual.
https://www.codeigniter.com/user_guide/t...pages.html
https://www.codeigniter.com/user_guide/g...llers.html
https://www.codeigniter.com/user_guide/g...views.html

If you still have any problems, you NEED to post some code and what URL you try to access.

Thank you jreklund,


This My controller Code:


PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class 
Segway extends MY_Controller
{

  function __construct()
  {
      parent::__construct();

      if (!$this->loggedIn) {
          $this->session->set_userdata('requested_page'$this->uri->uri_string());
          $this->sma->md('login');
      }
      if (!$this->Owner && !$this->Admin) {
          $this->session->set_flashdata('warning'lang('access_denied'));
          redirect($_SERVER["HTTP_REFERER"]);
      }
  }

public function 
show_grid()
{
$db_conf = array();
$db_conf["type"] = "mysqli"// mysql,oci8(for oracle),mssql,postgres,sybase
$db_conf["server"] = "localhost";
$db_conf["user"] = "root";
$db_conf["password"] = "root";
$db_conf["database"] = "griddemo";

require_once(
"lib/inc/jqgrid_dist.php");
$g = new jqgrid($db_conf);

$grid = array();
// set table for CRUD operations
$grid["caption"] = "Test CI GRID";
$grid["rowNum"] = 10;//10,15 -- tinggi grid
$grid["shrinkToFit"] = true;
$grid["autowidth"] = true;
$grid["hidegrid"] = true;
//$grid["width"] = true;
$grid["height"] = 450;
#$grid["sortorder"] = "desc";
$grid["toolbar"] = "top";
$grid["add_options"] = array("recreateForm" => true"closeAfterEdit"=>true'width'=>'750''top'=>'150''left'=>'200');
$grid["edit_options"] = array("recreateForm" => true"closeAfterEdit"=>true'width'=>'750''top'=>'150''left'=>'200');
$grid["view_options"] = array("recreateForm" => true"closeAfterEdit"=>true'width'=>'750''top'=>'150''left'=>'200');
$g->set_options($grid);

$g->set_actions(array(
"add"=>true// allow/disallow add
"edit"=>true// allow/disallow edit
"view"=>true// allow/disallow edit
"delete"=>true// allow/disallow delete
"rowactions"=>true// show/hide row wise edit/del/save option
"export_excel"=>true// show/hide export to excel option
"export_pdf"=>true,
"autofilter" => false// show/hide autofilter for search - advance, false,true
"search" => false// show single/multi field search condition (e.g. simple or advance)
"inlineedit" => true
)
);

// render grid
$g->select_command "select * FROM clients";
$g->table "clients";
$g->set_columns($cols);

$data['grid'] = $g->render("list1");
//$this->load->view('grilla',$data);
    $this->load->view('themes/default/views/show_grid',$data); // For circle 404 page

}





And my View code:


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>

<style type="text/css">

::selection { background-color: #E13300; color: white; }
::-moz-selection { background-color: #E13300; color: white; }

body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}

code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}

#body {
margin: 0 15px 0 15px;
}

p.footer {
text-align: right;
font-size: 11px;
border-top: 1px solid #D0D0D0;
line-height: 32px;
padding: 0 10px 0 10px;
margin: 20px 0 0 0;
}

#container {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
}
</style>
</head>
<body>

<div id="container">
<h1>Welcome to CodeIgniter!</h1>

<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo  (ENVIRONMENT === 'development') ?  'CodeIgniter Version <strong>' CI_VERSION '</strong>' '' ?></p>
</div>

<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/themes/redmond/jquery-ui.custom.css"></link> 
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/jqgrid/css/ui.jqgrid.css"></link> 

<script src="<?php echo base_url() ?>lib/js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
<script src="<?php echo base_url() ?>lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

<div style="margin:10px">
<?php echo $grid ?>
</div>

</body>
</html> 

My URL: http://localhost/sma/segway

It's not openning, get error: 404 page not found

Attached imagen about my CI folder tree:


Thank you,

Regards


Attached Files Thumbnail(s)
   
Reply

#4
I'm not sure what your root url really are. I guess that the picture provided are 'sma' but you are trying to load a lib folder for Javascript that's not even included in the folder...

If the root folder indeed are inside 'sma' this should work.

In app\config\config.php:

Code:
$config['base_url'] = 'http://localhost/sma/'
$config['index_page'] = '';


index.php:

Code:
$system_path = 'system';
$application_folder = 'app';

$view_folder = '/absolute/path/to/your/themes/folder';
$view_folder = 'C:/absolute/path/to/your/themes/folder';


.htaccess:

Code:
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond $1 !^(index\.php|assets|files|update|updatepos|robots\.txt)
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

If it's not working or you already have this set it's your app\config\routes.php that's the problem.

Can you load the default controller?
http://localhost/sma/
Reply

#5
You can name a different view folder location in the index.php file look in there.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#6
(01-12-2018, 02:30 AM)jreklund Wrote: I'm not sure what your root url really are. I guess that the picture provided are 'sma' but you are trying to load a lib folder for Javascript that's not even included in the folder...

If the root folder indeed are inside 'sma' this should work.

In app\config\config.php:

Code:
$config['base_url'] = 'http://localhost/sma/'
$config['index_page'] = '';


index.php:

Code:
$system_path = 'system';
$application_folder = 'app';

$view_folder = '/absolute/path/to/your/themes/folder';
$view_folder = 'C:/absolute/path/to/your/themes/folder';


.htaccess:

Code:
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond $1 !^(index\.php|assets|files|update|updatepos|robots\.txt)
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

If it's not working or you already have this set it's your app\config\routes.php that's the problem.

Can you load the default controller?
http://localhost/sma/

Default controller is welcome: Ok.
In app\config\config.php: Ok
.htaccess: Ok
$view_folder = 'themes';

when update $view_folder to absolute path show error 500.

Thanks by your help
Reply

#7
Have you modified the view() function inside the Welcome controller?
Generally you ignore the view_folder name, so it should look like this.

PHP Code:
$this->load->view('default/views/show_grid',$data); // For circle 404 page 

You can also change the debug/log option inside app\config\config.php to see all error messages.
Logs are located in app\logs\
PHP Code:
$config['log_threshold'] = 4

If you just specify $view_folder = 'themes'; it will look inside app folder after it, not the root folder. Do you have a themes folder inside app too?

Can you load your site with the following URL? If so, your webbserver aren't loading your .htaccess file.
http://localhost/sma/index.php/segway

Can you post your app\config\routes.php
Reply

#8
Can you load your site with the following URL?
Not: 404 error page not found

Do you have a themes folder inside app too?
Not: THEMES folder it's in root folder.

routes.php - code


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
| $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'welcome';
$route['404_override'] = 'errors/error_404';
$route['translate_uri_dashes'] = FALSE;

$route['users'] = 'auth/users';
$route['users/create_user'] = 'auth/create_user';
$route['users/profile/(:num)'] = 'auth/profile/$1';
$route['login'] = 'auth/login';
$route['login/(:any)'] = 'auth/login/$1';
$route['logout'] = 'auth/logout';
$route['logout/(:any)'] = 'auth/logout/$1';
$route['register'] = 'auth/register';
$route['forgot_password'] = 'auth/forgot_password';
$route['sales/(:num)'] = 'sales/index/$1';
$route['products/(:num)'] = 'products/index/$1';
$route['purchases/(:num)'] = 'purchases/index/$1';
$route['quotes/(:num)'] = 'quotes/index/$1'

Thanks!
Reply

#9
Try this:

PHP Code:
$view_folder '../absolute/path/to/your/themes/folder'
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#10
Totally forgot you will need to access your Segway class this way.
http://localhost/sma/segway/show_grid
http://localhost/sma/index.php/segway/show_grid

Codeigniter only loads the index() function on default.
You can overwrite the default function by placing this in your route.
PHP Code:
$route['segway'] = 'segway/show_grid'

I thought you got a "real" 404 and not Codeigniters 404 messages. But had a look at my dev machine at home now.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.