I use CI v2.0.3 , xampp windows 1.7.0 , and I renamed the CI folder to "Hello"
I created a Blog.php at application/controller.
The content of Blog.php is:
<?php
if(!defined('BASEPATH')) exit('No Direct Script Access Allowed');
class Blog extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
echo "Haloo.. CI pertama";
}
}
I want to access localhost:8080/hello/index.php/blog or localhost:8080/hello/index.php/Blog but both of them still show 404 not found.
This is what I expect instead: "Haloo.. CI pertama".
If your CI folder is named 'Hello' then you access it like this:
http://localhost:8080/Hello/index.php/blog
Whatch out! the folder name is case sensitive so /hello/index.php/blog will not work
The URL you have entered isn't correct if you haven't enabled the Rewrite module for Apache. For your settings considering the folder name also try:
http://localhost:8080/Hello/index.php?/blog
Edit: Folder name added
You need to render a view in your index action.
Your views are located in application/views. So you'll have to create a file called index.php there in which you'll put Hello World. And then you'll add this to your function:
$this->load->view('index');
Hope this helps.
Related
I'm new in Codeigniter I'm not sure how to use Codeigniter Routing. I've created the Contact.php in the controller folder and contact.php in the views folder.
In routes.php I have put $route['Contact'] = 'controller/contact'; but when I enter the url http://mytest.dev/contact/ it shows 404 Page Not Found. The page you requested was not found.
I want when I enter "http://mytest.dev/contact" it will show the contact page
Thanks in advance.
Controller
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Contact extends CI_Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->load->view('contact')
}
}
In CI there is an index.php in the URL ( by default ). So, you can access your page with this url http://mytest.dev/index.php/contact
For removing it from URL and have it like you want you need to add .htaccess file in your project directory
Check this answer for it
Also, you don't need to change your routes.php every time after creating a new page. Leave it like this
$route['default_controller'] = 'welcome'; // or contact
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I see you are using $route['Contact'] = 'controller/contact';
Tell us your controller's class name and which function/method did you use from the above you are referencing to contact() and that controller name doesn't make sense. You route will normally be in lowercase too.
If you named your class Contact (which seems like it) then you need to put a .htaccess file in the folder where your index.php or base_url resides (or root directory) and then remove the value in application/config.php as $config['index_page'] = ''; so that you can access it from http://mytest.dev/contact
To make it clearer. The format should be $route['AAA'] = 'BBB/CCC';
AAA is the url path of your choice
BBB is the name of your controller's class
CCC is the function/method of the page you want to show
If you didn't add the htaccess, you must put /index.php/ before your preferred path.
I'm new in php coding and I'm using Yii2 framework
I'm trying to make a simple project as follow:
I added a .php file named "PostController.php" in the backend/controllers and I wrote this codes in this file:
<?php
namespace backend\controllers;
use yii\web\Controller;
class PostController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
?>
and I created a file in beckend/views named "post" and in this folder I created a.php file named index.php
then I just wrote one line in index.php for test as bellow:
<h1>Hello World</h1>
Now I want to see this index file (Hello World) in my browser. Which url I should enter in my browser to see that? I tried the bellow url and it didn't worked!:
projectname.loc/index.php?r=post/index
if pretty url is true then you have to access the controller like
localhost/projectname/backend/web/index.php/controller/action
if pretty url is false then you have to access the controller like
localhost/projectname/backend/web/index.php?r=controller/action
if you project is in your local machine, if its on your server then you have to write server name instead of localhost
You should go to projectname.loc/post (or projectname.loc/post/index), to be in this action. before that you have to turn on the "prettyUrl" in your urlManager
If you use basic tamplate from yii2 your namespace must be app/backend/controllers and you should go to projectname.loc/index.php?r=backend/post/index
"backend" it will be a path to your controller, not a module
I am new to codeigniter and really interested in trying it out. I followed the guide but ran into a problem. It seems like I am unable to load my first page properly.
I have inside the view folder another folder called general and inside it index.php.
in controller folder, I have sub-folder with general and inside it is Default controller.
I have the following route and yet the page showing is blank
$route['default_controller'] = "general/default";
$route['404_override'] = '';
When I visit the link, I type this in browser:
http://localhost:8888/treventa/
and the screen is blank. Am I doing something wrong? Sorry if this is too simple but a person got to learn from his mistake :)
Try with me step by step:
Firstly: the Controller:
(main.php) File content
if (!defined('BASEPATH'))exit('No direct script access allowed');
class Main extends CI_Controller {
public function index() {
$this->load->view('general/welcome');
}
}
Secondly: The view:
(welcome.php) File content
You can put anything you want
<h1> Hello, I'm the view file </h1>
Finaly: The routes:
(routes.php) File content
$route['default_controller'] = "general/main";
Now call the script like this http://localhost/codeIgniter/, that's where codeIgniter is the script folder name.
I think everything now is clear.
CI trying to use method default() of general controller. If You want to use folders for controllers, make sure You specify method, so try $route['default_controller'] = "general/default/index";
And one more thing: this method (default_controller) will be used when You trying reach Your root http://localhost:8888/, if You want to route request from http://localhost:8888/treventa/ to default controller, You need to add route-rule to /config/routes.php something like $route['treventa'] = "general/main/index";
I'm getting a 404 Page Not Found error in CodeIgniter\WAMP after doing the following:
renamed a controller (from welcome.php to search.php)
renamed the view to load from search.php as *search_page* (see below)
renamed the related view (from *welcome_message.php* to *search_page.php*)
renamed the default controller in config\routes.php to search
restarted WAMP
search.php
public function index()
{
$this->load->view('search_page');
}
config\routes.php
$route['default_controller'] = "search";
Where did I go wrong?
i'm not a codeigniter programmer, but you should make the class Search -> class Search extends CI_Controller, no? found it on this link -> http://ellislab.com/codeigniter/user-guide/general/controllers.html
i think it's the same in every framework, cakephp, codeigniter, zend etc.
hi my folder sturcture is like this
controllers/user/registration/register.php
Inside the register.php controller there is let say for test index function saying 'hello world'.But i cant access the folder index through browser.
My base_url is
$config['base_url'] = 'http://localhost/new/';
But while i write
localhost/new/index.php/user/registration/register/index
I got an error
The page you requested was not found.
what is weird is, I can access the controller fxn of user folder but cant access the controller fxn inside registration folder .And for default controller i have 'home.php'
$route['default_controller'] = "home";
$route['404_override'] = '';
I just want to access the controller/user/registration/register/index fxn which says 'hello world' but it says an error-'The page you requested was not found'.
Thanks
Codeigniter only supports a single level directory structure for Controllers.
Try this link below for Multi Level Subfolder Controller in CodeIgniter :
Multi Level Subfolder Controller in CodeIgniter
Ok after writing some hunch code in my test project ,finally it worked in my case
So here it goes
I follow this link Multi Level Subfolder Controller in CodeIgniter(thanks to K u s h)
http://glennpratama.wordpress.com/2009/10/20/multi-level-subfolder-for-controller-in-codeigniter/
and copy the code and paste in my new/application/core/MY_Router.php as told in that link
and an error came to me like this
Call to undefined method CI_Router::CI_Router() in C:\xampp\htdocs\new\application\core\MY_Router.php
So i changed a little portion of that code to
// Function MY_Router()
// {
// parent::CI_Router();
// }
public function __construct()
{
parent::__construct();
// Your own constructor code
}
And after i was able to access the controllers/user/registration/register.php index fxn
It worked in my case.Thanks to all