0
votes

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?

3
We need a view file to render page view. If you don't like to render or display page means you wants to use that function or action, then you can easily prevent rendering view as '$this->autoRender = false'. If you set autoRender to false, you will not get 1st error. - Fazal Rasel
your question is "Should I create a new controller in cakephp", but your problem is with views... it's kind of confusing - Nunser
Sounds like you want to use the pages controller - You would ordinarily only edit home.ctp to change your home page contents, and only create view files in that folder to access your /pages/<page_name>. You don't need a specific controller, or controller action, to action to do that. Unless you disable it, CakePHP will render the view corresponding to the controller-action by default. - AD7six

3 Answers

1
votes

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.

1
votes

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

0
votes

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