Trying to remove /events/view/ from url

I am using cakePhp 2.8.2. I am not sure where to start here. I have read about using the routes.php to be able to remove the /events/view/ part of the URL but not sure if this is as simple as it’s made out to be and also the .htaccess file.

The url string looks like this in my test project:

http://localhost:8888/rootfolder/events/view/united-kingdom/london/image/image-moved-to-bottom

and I am trying to do this:

http://localhost:8888/rootfolder/united-kingdom/london/image/image-moved-to-bottom

my .htaccess is:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

My routes.php is like this:

if (!file_exists(APP.'Config'.DS.'database.php')) {
Router::connect('/*', array('plugin' => 'install' ,'controller' => 'install'));
}

Router::connect('/', array('controller' => 'events', 'action' => 'index'));
Router::connect('/about', array('plugin'=>null, 'controller' => 'pages', 'action' => 'display', 'about'));

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

Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));

Router::connect('/admin', array('admin' => true, 'controller' => 'settings', 'action' => 'dashboard'));

Router::connect('/feeds/*', array('controller' => 'feeds', 'action' => 'index'));

Router::connect('/lang/*', array('controller'=>'settings', 'action'=>'lang'));

CakePlugin::routes();

require CAKE . 'Config' . DS . 'routes.php';

Any help with this would be welcome, also if it’s not possible a confirmation it is not possible would also stop me from searching everywhere.

I should add that my ‘Events’ folder with’view.ctp’ is contained in the ‘View’ folder which is contained in the’app’ folder.

Why not template folder, then it wouldn’t show. In other words, view in Template folder, and make a layout under Layout folder to display it.

Not sure what you mean here. I think it’s not possible to just remove the /events/view/ so I am thinking of trying to rename them /e/v/ how is that possible?

Have you tried to put you view in the template folder, and make a layout file. Use proper naming conventions, and all should display just fine. See the blog tutorial part 2

<!-- File: src/Template/Articles/index.ctp -->

<h1>Blog articles</h1>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Created</th>
    </tr>

    <!-- Here is where we iterate through our $articles query object, printing out article info -->

    <?php foreach ($articles as $article): ?>
    <tr>
        <td><?= $article->id ?></td>
        <td>
            <?= $this->Html->link($article->title, ['action' => 'view', $article->id]) ?>
        </td>
        <td>
            <?= $article->created->format(DATE_RFC850) ?>
        </td>
    </tr>
    <?php endforeach; ?>
</table>

the view is in templates
Then read the docs on layouts something like

<!DOCTYPE html>
<html lang="en">
<head>
<title><?= h($this->fetch('title')) ?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Include external files and scripts here (See HTML helper for more info.) -->
<?php
echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');
?>
</head>
<body>

<!-- If you'd like some sort of menu to
show up on all of your views, include it here -->
<div id="header">
    <div id="menu">...</div>
</div>

<!-- Here's where I want my views to be displayed -->
<?= $this->fetch('content') ?>   //////////////THIS IS DISPLAYING THE VIEW////////////////////

<!-- Add a footer to each displayed page -->
<div id="footer">...</div>

</body>
</html>

Hi Jim,

Thanks for trying to help. The issue is to do with the routes.php I have done a simple fix by renaming the /view/ file but don’t know how to do the /events/ part which is the controller.

Don’t worry about it.

you cane it anything you want in routes like

$routes->connect('/dog/doglist/', ['controller' => 'Dogs', 'action' => 'dogList']);

could be changed to

$routes->connect('/happyzappy/', ['controller' => 'Dogs', 'action' => 'dogList']);

then mysite/happyzappy would show the doglist.

Ha! ha! thanks for that it made me laugh.

Seriously let me see if I can get that to work and come back again.

Appreciate the humour, let’s see if it will work for me now…

G

Ok that’s not what I want.

$routes->connect('/dog/doglist/', ['controller' => 'Dogs', 'action' => 'dogList']);

I want the /dog/ name changed.

My set up is root folder with app.

then when I go to the webpage it shows the site name www.example.com

But when I trigger a link it would be www.example.com/doglist/view/etc1/etc2/etc3

I want the routes to make the URL show:

www.example.com/etc1/etc2/etc3