Default route controller/action and links to css/js do not work cakephp

Asked

Viewed 1,190 times

0

After extracting cake 2.5.2 to the directory (Linux) /var/www/html/teste when accessing the url http://localhost/teste it loads the contents correctly from the controller pages and action display according to the file routes.php:

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));

But when trying to access the controller directly from the url :

http://localhost/teste/pages/display have Return 404 from Page not found.

Other than that(rs), the css/js/img webroot (not being included by the generated url) are not loaded.

Generated url that returns file not found:

http://localhost/teste/css/cake.generic.css

Url to access the file correctly:

http://localhost/teste/app/webroot/css/cake.generic.css

My solution for the css/js/img files was the following, I changed the way to call the file.

Standard form used:

echo $this->Html->css('cake.generic');

New form:

echo $this->Html->css('/app/webroot/css/cake.generic.css');

In short, I think maybe the error really is in apache or something like that, but I don’t know exactly how I can validate that part.

My solution for css/js/img, is that correct? Because I think it was supposed to work like the example I downloaded in the cake version correctly.

In case you need more information just say the word, thanks.

  • Alessandro, the display method cannot be called, it is a "subcontroller" it does not render anything, only directs to the correct view.

1 answer

1

You need to call the views from PagesController in this way:

http://localhost/teste/pages/home

The method display does not return view, you direct request in the url the view you want to display, after the controller /pages/sua_view.

As for css/js/img, usually just call it that:

echo $this->Html->css(array('forms', 'tables', 'menu'));

Will output:

<link rel="stylesheet" type="text/css" href="/css/forms.css" />
<link rel="stylesheet" type="text/css" href="/css/tables.css" />
<link rel="stylesheet" type="text/css" href="/css/menu.css" />

If this is not happening, it may be that your server is not properly configured to use cake.

Take a look here: http://book.cakephp.org/2.0/en/installation/url-rewriting.html

  • So, man, I tried like you said, I even changed my action to index and the view name too.. but always from the 404, already on the css, it creates right the link as you said, but it does not find the file, it only finds by the url http://localhost/teste/app/webroot/css/cake.generic.css by inserting the app/webroot folder first, you think it might be something in . htaccess?

  • Did you set up the server as the site reports? Check to see if it generated the files. htaccess, could be yes, one of them is exactly responsible for directing these requests to the webroot folder.

  • I just don’t understand one thing, Pagescontroller is for static pages, no methods(actions), if you create methods, it will only be accessible by the controller you create.

  • I’m taking a look at the link guy, it may be that the solution of my problem really is here hehe, about the controller I used this as an example because it came with the project, but I created another one with the name of my object extending Appcontroller and still can’t access controller/action

  • It is because it is not properly configured, the . htaccess is fundamental, without it nothing more scrolls..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.