如何在 config/app.php 文件中的 cake php 3 中设置基础 url 并在所有视图中获取 url
how to set base url in cake php 3 in config/app.php file and get that url in all view
我想将基础 'url' 设置为 "codeigniter" 并且可以在所有视图中访问。我想要像“http://localhost/somepath”
这样的完整 url
您可能不需要这样做,因为 Cake 中的 Helpers
会自动完成。
例如,如果您的应用在 http://localhost/somepath 下,创建一个 link 像这样
echo $this->Html->link('home', '/');
会自动指向http://localhost/somepath
操作链接的工作方式相同:
echo $this->Html->link('login', ['controller' => 'Users', 'action' => 'login']);
会自动指向http://localhost/somepath/Users/login
如果您确实需要在视图以外的任何地方获取 url,您可以这样做:
use Cake\Routing\Router;
$path = Router::url('/', true);
在 CakePHP 3 中您可以在
中定义 "BASE_URL" 常量
yourAppFolder/config/paths.php as
define('BASE_URL', 'www.yoursite.com/');
并在项目的任何位置使用 BASE_URL
。
我想将基础 'url' 设置为 "codeigniter" 并且可以在所有视图中访问。我想要像“http://localhost/somepath”
这样的完整 url您可能不需要这样做,因为 Cake 中的 Helpers
会自动完成。
例如,如果您的应用在 http://localhost/somepath 下,创建一个 link 像这样
echo $this->Html->link('home', '/');
会自动指向http://localhost/somepath
操作链接的工作方式相同:
echo $this->Html->link('login', ['controller' => 'Users', 'action' => 'login']);
会自动指向http://localhost/somepath/Users/login
如果您确实需要在视图以外的任何地方获取 url,您可以这样做:
use Cake\Routing\Router;
$path = Router::url('/', true);
在 CakePHP 3 中您可以在
中定义 "BASE_URL" 常量yourAppFolder/config/paths.php as
define('BASE_URL', 'www.yoursite.com/');
并在项目的任何位置使用 BASE_URL
。