I am working on CakePHP 2.7. I have to show some static menu on every page. Since, the menu contains lot of sub menus, I want to keep them in a separate file navigation.ctp and show them on default.ctp
I tried extend and elements but none of them give expected result.
Note : This is not dynamic menu and I am not fetching them from database.
Place your navigation.ctp inside app/View/Elements/
Then, inside your default.ctp, include the element as follows:
<?= $this->element('navigation'); ?>
Note that if you need any variables within the element, you may need to pass them through inside an array as a second parameter, such as:
<?= $this->element('navigation', array(
"varible_name" => "variable_value"
)); ?>
I'm having some issue of using ExtJS-5 to set some Hyberlink which also could be dynamically changed(according to a REST GET call).
Now I'm able to set a label as a Hyberlink using it's 'html' config which makes it clickable and jump to another page. Also according to the DOC file, if I assign the 'text' config to a 'Label' it will disable the 'html' property and only display the 'text'. So now I can change the 'text' of label Dynamically but they are not clickable.
Questions:
Should I use 'Label' for what I'm trying to do or use something else?
DOC shows 'Label' has no getText or getHTML method, then how to read its 'value'? like I want to pass it to the BackEnd. (getValue() doesn't work)
Label is perfectly fine for doing this
ExtJS doesn't provide any method of getting text value, cause we can read it directly
How can I go about overiding CakePHP's code without creating it manually myself? I'm attempting to customise the getCrumbList function.
The lastClass option is applying a class to the 'li' tag sucesfully, but I'd also like to remove the link/ ahref altogether for the last tag.
Function generating crumbs
echo $this->Html->getCrumbList(array('class' => 'breadcrumb', 'lastClass' => 'active'), 'Home');
Output of getCrumbList
<ul class="breadcrumb"><li class="first">Home</li><li>Scheduler</li><li class="active">Downloaded Playlists</li></ul>
Simple solution - You dont include the URL in addCrumb. Doh!
I'd like to create well formatted Form element with Form helper but without creation of form itself. So i wrote:
$this->Form->input(
'Kid.id',
array(
'type' => 'text',
)
);
This is ajax inside "Kids" controller response, and I'd like to update form after user make some actions.
I have no idea how to do it, except manually write HTML code.
Shame on me. This works I just forgot to add an echo at the beginning of line.
Are there any approaches to set in model field label? I dont want use 'label' property in form helper.
Please make sure I understand this correctly, you want to set a field label in the model, rather than using the form helper?
That violates basic MVC architecture. While Cake is flexible on some things, I don't think this is a possible option. I also don't see why you'd want to do it -- is there some reason that you don't want to use the label property in the form helper?
The basic issue is that the label for a form is part of the presentation layer, while the model represents the data. As such, it isn't possible (and I can't think of a situation where it'd make sense...) to assign a label to a data field which would then be used whenever that field is output.
If I misunderstood your question, please clarify.
What I do is setting up a convention in my models. I added a public attribute called "fieldLabels" to all the models, to assign default text labels for generic forms.
Example:
class MyModel extends AppModel {
// ...
public $fieldLabels = array(
'username' => 'User name',
'email' => 'e-mail address',
'phone' => 'Phone No.',
);
// ....
}
Then I pass around the labels to the view and use the extra parameter for the input, as sibidiba said:
echo $this->Form->input('title', array(
'label' => $fieldLabels['title'] . ': ',
));
In case I need special labels, I'll handle each case as an exception. Of course, if you want internationalization, that's a whole different topic.
Do you want to set the label's value? This is done in the view, but of course the value can originate from the controller/model. Like this:
echo $this->Form->input('title', array(
'label' => $titleLabel,
));
you can also disable the label element:
echo $this->Form->input('title', array(
'label' => null,
));
Not 100% sure, but I think you might be looking for Model::displayField
i suggest u directly use the helper u want.. bcos $form-input() creates div .. labels..
i personally had to weed out this on each line
with the direct helper like
$form->text()
$form->textarea()
$form->select()
u can keep the code much cleaner.
Note: $form->input saves time when used right...