Well< I try to run CodeIgniter on my localhost with MAMP. I've changed base_url in config.php on $config['base_url'] = 'http://localhost:8888/codeigniter';
Also I've created blog.php as in tutorial I use:
<?php
class Blog extends Controller {
function index()
{
echo 'Hello World!';
}
}
?>
But, when I go to http://localhost:8888/codeigniter/index.php/blog/, there is output of my index.php ('test' - string) but there is no hello world there, what am I doing wrong?
the biggest breaking change between Codeigniter 1.7 -- which many tutorials are based on -- and Codeigniter 2 is the first line of code in the controllers and models
class Blog extends Controller {
change that to
class Blog extends CI_Controller {
same for models
class Donotmakemodeljokes extends CI_Model {
Related
I have checked the controller name and method name but still it says "The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again."
I have tried this url's given below and got this error:
http://localhost/framework/index.php/helloworld
http://localhost/framework/helloworld/index
File under Controller name is: Helloworld.php
<?php namespace App\Controllers;
use CodeIgniter\Controller;
class Helloworld extends CI_Controller
{
public function index()
{
echo 'Hello World!';
}
enter image description here
Change
class Helloworld extends CI_Controller
to
class Helloworld extends Controller
in CI4 CI_Controller renamed as Controller
If You are trying Codeigniter 4 without using htaccess you should call like
http://localhost/framework/public/helloworld
Or you should run the Codeigniter using this Command
php spark serve
After that go to browser check http://localhost:8080
You should learn the basics of codeigniter 4 From here
How to Use codeigniter 4
Hope this Helps
Please try after performing below changes -
Remove use statement.
Extend BaseController as CI_Controller is not available in CI4.
Return what you want to show on the screen.
<?php namespace App\Controllers;
class Helloworld extends BaseController {
public function index() {
return 'Hello World!';
}
}
In the the majority of comments, it was stated that all you had to do was to rename your CI_Controller to plain simple ole Controller ( as per the CI 4 User guide ) and what you declared in your "use".
So you would have
<?php namespace App\Controllers;
use CodeIgniter\Controller; // This is what you are "use"ing
class Helloworld extends Controller { // And this is where you are "use"ing it
public function index() {
echo 'Hello World!';
}
}
See the difference?
I installed Cakephp as part of my tutorial, and I wanted to start a basic page with only hello world.
I written the class in the Hellopagecontroller.php < a file i created:
<?php
class HelloController extends Controller
{
public function index()
{
echo "Hello, CakePHP World";
}
}
?>
An image to illustrate:
An image of the files I
This is the output I have when opening the index page it doesn't show hello, cakephp world rather
Error: Class 'Controller' not found File
/Applications/XAMPP/xamppfiles/htdocs/Test2/src/Controller/HelloController.php
Line: 5
The error I am getting
note: cakePHP version: 3.4.6 - PHP Version:5.6.28
You are missing out to declare the namespace, and you should extends your class from AppController.
If you are new on CakePHP framwork, I highly recommend you check the Bookmarker Tutorial out.
<?php
namespace App\Controller;
class HelloController extends AppController
{
public function index()
{
echo "Hello, CakePHP World";
}
}
?>
Remove all spaces before start of php tag will remove this problem.
Hi I'm pretty new to MVC framework. I decided to build a small application in MVC to get better understanding.
I googled around and found PIP framework that i can use for simple application and then modify once i will get complete understanding.
PIP can be found here
Now i have one question that by looking to PIP framework, do i need to design to new controller for every page that i will use.
For e.g
applications/
views/
home.php
about.php
contact.php
controllers/
main.php
aboutus.php ??
contactus.php ??
For eg. my default controller and view is main.php and home.php and i have a controller for main.php as below:
<?php
class Main extends Controller {
function index()
{
$template = $this->loadView('home');
$template->set('title', "Welcome Homepage");
$template->render();
}
}
?>
So, in this way, do i need to create new conrollers for about and contact.php
PIP's routing is internalized and requires a specific scaffolding of your controllers:
When you go to:
example.com/main
It looks for the controller main and then the function index by default.
If you were going to have 1 controller per view, then it would be something like:
example.com/main
class Main extends Controller
example.com/about
class About extends Controller
example.com/contact
class Contact extends Controller
However, if you went with a default page controller, this would greatly simplify the scaffolding:
example.com/page/{about|contact|main}
class Page extends Controller {
public function about (){
}
public function contact(){
}
public function main(){
}
}
Now 1 controller will handle the delivery of each of these pages.
With pip the URL defines the controller and function that will be executed. If you want the contact page to be at mysite.com/contact, you do need to add a Contact controller.
You do not need to create a new controller for every page. Lets assume you had a forum. You could have the following urls:
mysite.com/blog/write
mysite.com/blog/view/15
These different URLs would all be handled in one controller, blog.php
<?php
class Blog extends Controller {
public function write()
{
echo 'Hello World!';
}
public function view($postId)
{
echo 'Viewing post: ' . $postId;
}
}
I also used PIP as a starter framework, and extended it to include some additional functionality. I even started to document my efforts, but other projects have taken me in other directions.
Happy to share what I have, and some documentation on my PIP efforts can be found at http://www.shed22.com/pip.
Let me know if you would like a copy of the source code and a sample application.
Stephen
I had a working project uploaded to server 2 week before. It was working fine until now. Below is code for model awsmodel.php
class Awsmodel extends MY_Model {
function __construct()
{
}
// some other functions
}
MY_Model again extends to CI_model.
class MY_Model extends CI_Model {
// required functions
}
From controller pages.php I am calling the function like below.
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
$this->load->view('home_pz',$data);
}
}
The above code suddenly stooped working today. After some test and tries, I got to know that when I comment below 2 lines from controller function then The page loads.
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
I have changed environment variable to 'development' and tested but still no error message shows. In firefox its showing a blank page, where as in chrome it shows 500 server error. The same code was working since 2 weeks. Don't know why its not working now. If anyone can help me out ?
I am using CI version 2.1.4
If you using CI 3.0 please load model like this
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('awsmodel'); //as your model filename: awsmodel.php
$data['featured'] = $this->Awsmodel->featuredProp();
//$data['featured'] = $this->awsmodel->featuredProp();// for CI version 2.1.4 –
$this->load->view('home_pz',$data);
}
}
i installed fresh cakephp. its app controller working fine. but when i write my controller and its view but this result in page not found. My code is given below
class PostsController extends Controller {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
and create folder named Posts in view folder and over there create index.ctp file as well. but its result in page not found. Please help what may be mistake by me or is there any need to configuration. Thanks
Your controller should be named PostsController.php (ie plural)
Just spotted it, you need to extend AppController in CakePHP 2.x, not Controller: ie:
class PostsController extends AppController {
there might problem apache rewrite module. if you are using WAMP, just put on your rewrite module.