How to make cakephp 3 url ready for marketing?

不羁的心 提交于 2019-12-25 01:54:32

问题


I am new for cakephp. I am trying to rewrite the url to make it SEO friendly.

I have create module in cakephp3 for cms page.

Page Table - url field would like to use as "about-us"

CREATE TABLE IF NOT EXISTS `pages` (
  `id` int(11) NOT NULL,
  `title` varchar(100) NOT NULL,
  `detail` text NOT NULL,
  `url` varchar(225) NOT NULL,
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1;

Current URL (working)- https://example.com/pages/view/8

I want to make this like below. https://example.com/about-us

Please suggest.


回答1:


In your cakephp3 folder, there is a file "routes.php" in \config.

Open the "routes.php" and use:

use Cake\Routing\Router;

// Using the scoped route builder.
Router::scope('/', function ($routes) {
    $routes->connect('/about-us', ['controller' => 'Pages', 'action' => 'view', 8]);
});

// Or using the static method.
Router::connect('/about-us', ['controller' => 'Pages', 'action' => 'view', 8]);



回答2:


in side route::

Router::scope('/', function ($routes) {
$routes->connect('/:title', ['controller' => 'Pages', 'action' =>  'home'],['pass' => ['title']]);
});

//in PagesController

public function home($title=NULL){ 
        echo $title;//title = 'yogendra'
}

browser url:: http://localhost/project-name/yogendra you can compare title with you DB table and display page dynamically Hope you fixed the issue. :)



来源:https://stackoverflow.com/questions/48146369/how-to-make-cakephp-3-url-ready-for-marketing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!