【问题标题】:How to make cakephp 3 url ready for marketing?如何使 cakephp 3 url 为营销做好准备?
【发布时间】:2018-06-17 04:48:10
【问题描述】:

我是 cakephp 新手。我正在尝试重写 url 以使其对 SEO 友好。

我在 cakephp3 中为 cms 页面创建了模块。

Page Table - url 字段想用作“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;

当前 URL(工作)- https://example.com/pages/view/8

我想像下面这样。 https://example.com/about-us

请提出建议。

【问题讨论】:

标签: php cakephp-3.0 cakephp-3.1


【解决方案1】:

在您的 cakephp3 文件夹中,\config 中有一个文件“routes.php”。

打开“routes.php”并使用:

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]);

【讨论】:

  • 我得到了你的建议。你能告诉我如何让它动态,因为我不能写 100 页
【解决方案2】:

在支路::

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

//在PagesController中

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

浏览器网址::http://localhost/project-name/yogendra 您可以将标题与您的数据库表进行比较并动态显示页面 希望你解决了这个问题。 :)

【讨论】:

    猜你喜欢
    • 2011-12-18
    • 1970-01-01
    • 2011-03-14
    • 2013-07-09
    • 1970-01-01
    • 2017-06-12
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多