user1227544
user1227544

Reputation: 11

Should I create a new controller in cakephp

I'm new in CakePhp but experienced in CodeIgniter. I created a controller in "WelcomeController.php" in controller directory and run the page. I got two errors 1. Error: The view for WelcomeController::index() was not found. 2. Error: Confirm you have created the file: C:\xampp\htdocs\myc\app\View\Welcome\index.ctp.

My question

  1. Why I am getting this error even though I have supplied index() function?

  2. In codeigniter we may not create a directory for a view. I don't want to create a directory "Welcome" in view. I there any provision provided?

Upvotes: 0

Views: 506

Answers (3)

heinkasner
heinkasner

Reputation: 425

Be sure that you have all the files and directories necessary for the modal, controller and view to link up correctly i.e.: Create the folder called welcome(s) in your views directory with an index.ctp file. This should get rid of that error.

Check out this brilliant blog tutorial: Link

Upvotes: 0

Nunser
Nunser

Reputation: 4522

1) You're getting that error because your missing the view, not the controller function. To fix, do what the error suggested:

Confirm you have created the file: C:\xampp\htdocs\myc\app\View\Welcome\index.ctp.

2) "I don't want to create a directory "Welcome" in view. I there any provision provided?".
Not really... I mean, no if you want that action to have a correspondent view to put the content. Otherwise you can use $this->autoRender = false to not show anything... But that'll mean the url localhost/welcomes/index will be blank.

I recommend you read the basics as Fazal said. I know every framework can give us "quirks" and we end up expecting every other framework to work the same way we are used to, but try to adapt to the cake-way.

Btw, should be "WelcomesController", according to cake conventions

Upvotes: 1

Fazal Rasel
Fazal Rasel

Reputation: 4526

In Cakephp you have to create view for function or here it called action. In your case, Create index.ctp on App->View->Welcome folder. This Getting Start will give you a basic idea.

Upvotes: 1

Related Questions