CakePHP plugin throws "Missing View" error but view file exits - php

I'm writing a basic plugin for my cakePHP 2.x app following the instructions in the book.
I've created the directory/file structure with a MyPluginAppController.php and MyPluginAppModel.php.
I added CakePlugin::load('MyPlugin'); to the parent app's bootstrap.php file.
Then I created one Controller and Model. But for some reason when I try to view mysite.dev/(admin)/my_plugin/my_model/ I get a "Missing View" error. It says to confirm that the view file exists, which it does!
I don't think I skipped any steps from the book. What am I doing wrong?
Update:
Controller path: app/Plugin/MyPlugin/Controller/MyModelController.php
View path: app/Plugin/MyPlugin/View/MyModel/admin_index.php
URL: http://mysite.dev/admin/my_plugin/my_model/

Rename this file
app/Plugin/MyPlugin/View/MyModel/admin_index.php
To this extension .ctp
app/Plugin/MyPlugin/View/MyModel/admin_index.ctp
This is a common mistake.

I was't using a plugin so my case was a bit different. However, this question shows up on the search results page, so I'll post this here.
This is the problematic controller.
<?php
class ArticlesController extends AppController {
public function beforeFilter() {
}
public function view() {
// do stuff
}
}
The problem:
CakePHP kept showing me the following error:
Missing View
Error: The view for ArticlesController::view() was not found.
Confirm you have created the file: Articles/view.ctp in one of the following paths:
Debugging:
I checked all paths it suggested using is_readable() and the stat command to make sure the view file exists and is indeed readable by PHP.
Solution:
The issue there is the empty beforeFilter(). As soon as I removed it everything worked.

Related

The technical reason is: No template was found. View could not be resolved for action "search" in class "LoginController"

Im new to typo3 and ive been trying to develop an extension for it. When I load the plugin to the page i get and error:
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be resolved for action "search" in class "LoginController".
In the login controller i have a function searchAction and I do have a template inside
\Resources\Private\Templates\StoreInventory\Search.html
What might be the error? I followed the documentation for extension development by typo3. I even downloaded the code from GIT and tried using that but no luck.
TL;DR: It should be placed at Resources/Private/Templates/Login/Search.html
explanation:
From your question I can tell you've used the documentation on https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/4-FirstExtension/6-adding-the-template.html
It is not wrong, but you've missed a vital step. When you take a look at the path they are using you'll see that a lot is done automagically. Let's break it down.
They have a controller with an action and a template related to it in the following path
controller:
\MyVendor\StoreInventory\Controller\StoreInventoryController
action: listAction
template: EXT:store_inventory/Resources/Private/Templates/StoreInventory/List.html
If you look closely you'll see that the template path is made up from several components.
the extension (EXT:store_inventory)
the default template directory path (Resources/Private/Templates)
The Controller name without the controller suffix (StoreInventory)
the Action name without the action suffix (List)
the .html suffix
If you take that information and apply it to your case it would be:
the extension (EXT:your_extension_name)
the default template directory path (Resources/Private/Templates)
The Controller name without the controller suffix (Login)
the Action name without the action suffix (Search)
the .html suffix
So the end result would be something like
EXT:your_extension_name/Resources/Private/Templates/Login/Search.html
It is true that you can use typoscript to change this behaviour or set overrides or extended templating for instance. But I think you're working from the default, and this should be the working path for you now
First check your templateRootPaths in Configuration/TypoScript/setup.typoscript
And set accordingly.
Try placing the file at \Resources\Private\Templates\Search.html as \Resources\Private\Templates is the default path unless you have altered it.

Codeigniter controller method 404 error

I cloned a copy of Codeigniter from github today using this link: https://github.com/bcit-ci/CodeIgniter.git. I am currently running MAMP setup so that http://localhost:8888 points to my htdocs folder. My root folder is called 'time'. When I go to http://localhost:8888/time/index.php, I do see the Codeigniter welcome page. Also, I can go tohttp://localhost:8888/time/ and see the same welcome page, even though I don't have an .htaccess file in the root directory.
Here is the problem. I added the following function to the Welcome.php controller class:
public function test()
{
echo 'Test';
}
This should display a page which shows 'test' when I visit http://localhost:8888/time/index.php/test. However, I get a 404 page not found error. Does anyone have any suggestions for understanding and fixing this problem?
Because localhost/index.php/test doesn't refer to the method test in the welcome controller. You would have to go to localhost/index.php/welcome/test or use routes.
They way you are doing it implies there is a controller named Test.php and it is trying to go to the index() function of that controller.

Unable to load controllers from another controller

I'm trying to load a controller inside another controller.
$data['com_top_menu'] = $this->load->controller('account/com_top_menu');
However, this seems to not work when I'm trying to load a controller that is located in the same folder as the controller I'm loading it from.
Tried loading controllers from other folders and seem to not load as well. It seams to load only from the 'common' controllers folder.
Edit:
Actually it seems that the controller is loading. If I place an echo in the middle of the loaded controller it will show the output before the template rendered. So, it looks like the controller is loaded and just doesn't output anything through the rendered view, unless it is a controller inside the common folder.
Files are all in place, controller loads, it just doesn't output anything through the view.
Few things for to load controllers-
1st - you can only load controller from same folders (admin/ catalog).
2nd - you can load controller from any subfolder, just need to pass correct loading path.
3rd - If Opencart hasn't that file than it will not display any error, result will be null/ false.
4th - If you are defining any function name then it will call that function else will call index function so in your case index.
5th - Please use this
return $this->load->view('your.tpl', $data);
Instead of
$this->response->setOutput($this->load->view('your.tpl', $data));
6th - Please enable your debug mode from php/ admin so that you will know any error if your code is throwing. Clear your error.log and then try to load controller.
7th - If these all points are code is not working then do 1 thing - add a blank controller with index function and just add one line so that you can return it's result from view then just
echo 'here';
In your view. If OC is not returning this result it's mean you have error in Opencart files else there is error in your code.
You can say these are same in a way (i am not saying completely and don't want to hurt anyone feelings ;)) but this code
$this->load->controller('account/com_top_menu');
is equal to (based on your autoloader)
$obj = new ComTopMenu; //assuming your class name
$data['com_top_menu'] = $obj->index();
so for your solution please check
- you have file com_top_menu.php in your catalog > controller > account >
- your file class name must be ControllerAccountComTopMenu (or any uppercase or lowercase combination but without _)
- your class must have index function because in your case it calling index.

Lithium PHP routes not working

I'm following the quickstart guide for Lithium: http://li3.me/docs/manual/quickstart
I created my posts Model in /var/www/my_app/app/models/Posts.php
<?php
namespace app\models;
class Posts extends \lithium\data\Model {
}
?>
I created my posts Controller in /var/www/my_app/app/controllers/PostsController.php
<?php
namespace app\controllers;
class PostsController extends \lithium\action\Controller {
public function index() {
return array('foo' => 'bar', 'title' => 'Posts');
}
}
?>
And I created my View in /var/www/my_app/app/views/posts/index.html.php
Lithium is less dense than <?=$foo;?>ium.
The quickstart guide then says that I should be able to view my posts index page by going to
http://localhost/my_app/posts
but I get a
Not Found
The requested URL /my_app/posts was not found on this server.
However, if I go to just
http://localhost/my_app
the default home page that comes with Lithium is displayed.
So I tried fixing the problem by adding this line to my /var/www/my_app/config/routes.php file:
Router::connect('/posts', 'Posts::index');
But I get the same Not Found error?
You need to make sure that mod_rewrite is installed and enabled in your Apache.
Also check that the .htaccess file is present and allow_override is properly set for the virtualHost, otherwise .htaccess files will be ignored.
For further information, check the troubleshooting section in the documentation
A little bit further in the Routing documentation, the parameters of the Router::connect() method are explained more fully. The portion after the :: should be the name of the action called by the route; in your case index (or perhaps nothing, if there's a default set for the indexAction; not familiar with Lithium). You derive the "name" by removing the suffix Action from your Controller's method name. I suggest exploring the Routing documentation more fully to save yourself headaches in the future.

Make redirect in Zend Framework 2 without template

I'm trying to make a redirect from route /admin to /admin/post/list.
I set a route from /admin to IndexController::indexAction()
Then I made controller like this
class IndexController extends AbstractActionController
{
public function indexAction()
{
$this->redirect()->toRoute('postList');
}
}
It works well, but ZF2 required to make a template index/index.phtml.
How I can do this redirect better, without empty templates?
If you add return it should work:
return this->redirect()->toRoute('postList');
I found initially that I couldn't make the return response option work at all, in spite of the docs and plenty of abortive attempts.
In the end I stripped out the default application module that I had included to bootstrap things "out of the box" but wasn't using for anything else, and after shifting the translator config and the factory for it, (as required by the error template - I suppose i could have removed even that, as not required) it started working.
Hey presto!

Categories