I have installed CakePHP on windows over II7 and i am having problems with the routes.
I have created a Model, a Controller and a View for Users.
When i try to access the index view, i do it like this without any problem:
http://myhost/cakephp/users/
But, when I try to add a new user, the view doesn't load properly:
http://myhost/cakephp/users/add/
It shows this error:
Error: AddController could not be found.
Error: Create the class AddController below in file: app\Controller\AddController.php
In order to make it work, i have to do this in app/Config/routes.php:
Router::connect('/users/add', array('controller' => 'users', 'action' => 'add'));
But that wouldn't be necessary if it worked well.
Neither the delete or view views load.
What's going on? How can i detect the problem?
Thanks.
EDIT
Content of routes.php:
Router::connect('/', array(
'controller' => 'pages', 'action' => 'display', 'home'
));
Router::connect('/pages/*', array(
'controller' => 'pages', 'action' => 'display'
));
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
Ok, it seems i have solved it. It was all because of adding a routing prefix using cake bake console... I had to comment this line at core.php
Configure::write('Routing.prefixes', array('users'));
Related
I'm working on a CakePHP 2.1 project and I have an issue concerning the "homepage" for admin panel.
When I enter : mysite.com/admin
I have a message telling me "AdminController cannot be found".
I declared this route in config/routes.php :
Router::connect('/admin', array('controller' => 'mycontroller', 'action' => 'index', 'admin' => true));
And when I enter mysite.com/admin/mycontroller as URI, it works.
Do you have an idea ?
Thank you in advance.
Edit | My routes.php file :`
/**
* Here, we are connecting '/' (base path) to controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/View/Pages/home.ctp)...
*/
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
/**
* Load all plugin routes. See the CakePlugin documentation on
* how to customize the loading of plugin routes.
*/
CakePlugin::routes();
/**
* Load the CakePHP default routes. Only remove this if you do not want to use
* the built-in default routes.
*/
require CAKE . 'Config' . DS . 'routes.php';
// Custom routes
Router::connect('/admin', array('controller' => 'jobapplications', 'action' => 'index', 'admin' => true));
As suspected, there are conflicting routes, namely the default routes provided by the core, which you are including via
require CAKE . 'Config' . DS . 'routes.php';
before defining your /admin route.
The defaults connect various routes that can cloak yours, for example:
Router::connect("/{$prefix}/:controller", $indexParams);
or
Router::connect('/:controller', array('action' => 'index'));
Long story short, order matters, move your route definition above the inclusion of the default routes.
I am new in cakephp, I want to call the plugin via the URL. Here is URL of
http://testproject.local/PluginName/ControllerName/ActionName
When I Run this URL at that time I found "Missing Controller" error.
Missing Controller
Error: <ControllerName>Controller could not be found.
Error: Create the class <ControllerName>Controller below in file: `app/Controller/<ControllerName>Controller.php`
It's showing me
`Exception Attributes: array ( 'class' => 'PracticeFusionController', 'plugin' => NULL, )`
Here is my routes.php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
* ...and connect the rest of 'Pages' controller's urls.
*/
Router::connect('/Pages/*', array('controller' => 'pages', 'action' => 'display'));
Router::connect('/gods/:action/*', array('plugin' => 'nova', 'controller' => 'gods'));
Router::connect('/gods', array('plugin' => 'nova', 'controller' => 'gods'));
Router::parseExtensions('json', 'xml');
Router::mapResources('events');
Router::connect('/<pluginName>', array('plugin' => '<pluginName>', 'controller' => '<ControllerName>'));
You can only load/open Plugin routes if you actually loaded the plugin in your project's bootstrap. You don't need to include a plugin route in your core app's routes.php. If you want to add plugin specific routes, you can load the plugin specific routes file, using the routes option. Note that by default all /plugin/controller/action routes are already routed properly, you don't need a separate routes file for that.
So, in your core app's app/Config/bootstrap.php, add:
CakePlugin::load('YourPlugin', array('routes' = true));
The routes from your plugin's Config/routes.php will then be loaded and can be used.
More details on this can also be found in the documentation.
If above solutions does not works, please load plugin like CakePlugin::load('YourPlugin', array('routes' => true)); Please note array passed is : array('routes' => true)
I have set-up a CakePHP application and included jQuery and jQuery Mobile to get mobile-friendly pages.
Now I'd like CakePHP also to react to AJAX responses and added RequestHandler to the $components. Strangely, if I move to another page, CakePHP just shows a blank page. If I then reload that page, the correct pages shows up. If I disable RequestHandler, everything works again as it should.
What am I doing wrong?
- I have added the JsHelper:
public $components = array(
'DebugKit.Toolbar',
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authError' => 'You must be logged in to view this page.',
'loginError' => 'Invalid Username or Password entered, please try again.'
));
public $helpers = array('Js');
and I also included
echo $this->Js->writeBuffer();
Jquery mobile expects to see a whole page on load. When you use RequestHandler you only get the contents from the view file not the layout
When i enter address: http://www.yourdomain.com/2 (without page:2)
It give you Missing View: (error)
Missing View
Error: The view for PagesController::display() was not found.
Error: Confirm you have created the file: /Users/username/Sites/mycakeapp/views/pages/2.ctp
Notice: If you want to customize this error message, create /views/errors/missing_view.ctp
In router config: (routes.php in config)
$chk = array('page' => '[0-9]');
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/:page/*', array('controller' => 'pages', 'action' => 'display'), array(
'page' => $chk['page'], 'pass' => array('page')
));
In pages_controller.php:
function display($on_page=1) {
$this->paginate = array(
'limit' => $this->Cookie->read('pagelimit'),
'page' => $on_page,
'order' => array(
'data.dateadded' => 'asc'
));
$data = $this->paginate('data');
$this->set('data', $data);
$this->render(implode('/', $path));
$this->set('title_for_layout', null);
}
Try adding all named parameters to the routes config manually:
Router::connectNamed(array('page'[, ...]);
Like the error message states, you need to have a file called 2.ctp in your pages folder.
Confirm you have created the file:
/Users/username/Sites/mycakeapp/views/pages/2.ctp
The display method in the pages_controller is generally used to display static pages. A file named with the param you send, in your case 2, followed by '.ctp' must exist in the view/pages folder, this is what the error message tells you.
If you where expecting something else, you are not doing it right.
I found problem solved. the answer is:
add in controller page:
$this->render('/pages/home');
no need to add Router::connectNamed
I'm having a strange routing problem with a site I just uploaded, and I've made a number of changes to test what's happening. It doesn't make any sense.
My setup is:
I'm using one plugin, which I've included all the routing in the routes.php file.
I've also included the routes for two other controllers, 'events' and 'updates'
they look like this:
Router::connect('/login', array('plugin' => 'pippoacl', 'controller' => 'users', 'action' => 'login'));
Router::connect('/logout', array('plugin' => 'pippoacl', 'controller' => 'users', 'action' => 'logout'));
Router::connect( '/events/', array( 'controller' => 'events', 'action' => 'index'));
Router::connect('/updates', array('controller' => 'updates', 'action' => 'index'));
What happens when I try to get to 'events' is that I get an error message saying:
"Not Found
Error: The requested address '/Events' was not found on this server."
I've checked the database and it's accessible, through the plugin's model/controller/view.
I've also made sure the model/controllers for 'events' and 'updates' are there.
Can anyone tell me how to trouble shoot this?
Thanks,
Paul
Do you open /events or /Events? URL-s - except the domain part - are case sensitive.
Thanks Sibidiba,
As it turns out this happened because there was a user model and user controller in the application folder as well as the plugins controller. So the routing treated other controllers as if they weren't there.
All fixed now.
Cheers, Paul