Search code examples
phpcakephpdirectory-structure

How to get the root directory of CakePHP?


I've got a view with a formular (which isn't created with the form helper). For example, I have CakePHP installed in a folder called 'myfolder1'.

So my formular starts with that line:

<form id="ctrlAddForm" method="post" action="/myfolder1/ctrl/add" accept-charset="utf-8">

But if I rename the root folder, I have to edit all formulars (2 yet). Is there any constant or function which represents the root directory / name?

I've read about the constant ROOT. Should I use that variable?

Solution

  1. You can define a constant ROOT_NAME in app\webroot\index.php with basename(ROOT).
  2. You can use the HTML Helper function url(). For example in the action attribute of the form tag:

    $this->Html->url(array('controller' => 'ctrl', 'action' => 'add'));


Solution

  • Well, you could try this normal ol' PHP function: basename

    basename(APP);
    

    Since that doesn't work I actually opened up my own Cake install. Try this:

    basename(dirname(APP));