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
basename(ROOT)
.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'));
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));
I had to get the URL of the CakePHP document root to use in Javascript, and I was able to set it up using the solution above:
<script language="Javascript">
$(document).ready(function() {
docRoot = '<?php echo $this->Html->url('/'); ?>';
}
</script>
and that piece of code - $this->Html->url('/')
- works perfectly in getting the root directory/URL for CakePHP.
This page has a list of the constants that can be used, http://book.cakephp.org/view/1141/Core-Definition-Constants
YOu can check the routes /var/www/yourprojectname/cake/conf/paths.php
you can get all constant variable are being used through the CAKEPHP.
I hope that helps.
Regards, Archit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With