I currently use zend_navigation via an XML file.
However I need to overwrite the previous breadcrumb to be its dynamic parent, in the controller.
Is this possible? It seems to me that zend_navigation is fairly static and the zend documentation keeps timing out.
Thanks
I have put:
public function addAction() {
$this->view->navigation()->addPage(array(
'type' => 'uri',
'label' => 'New page')
);
in my controller but no crumbbar shows up for that page.
Any ideas? $this->navigation() threw a
Method "navigation" does not exist and was not trapped in __call()
Also of note that my crumbBar is in my layout and not individual views.
Yes you can use an array.
What you should do really is create your array and then input it into the factory of the Zend_Navigation to create your pages for you.
Unfortunately my code is too complicated to show an example of how I used it. But I'll provide a simple example...
Once you create your navigation container, you can just add new pages to it.
Like
$this->navigation()->addPage(array(
'type' => 'uri',
'label' => 'New page'));
But you can also use addPages(). This is what I do.
I think you should just wait for the documentation to load back up for you and then look at that. Its really easy in fact.
When you have a more specific question, just ask that and give me a poke. I've had to use Navigation quite a lot so know it quite well.
Additionally, check out #zftalk on freenode. Theres lots of help on there.
// Disable Layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
// Output XML than HTML
$this->getResponse()->setHeader('Content-Type', 'text/xml; charset=utf-8');
$container = new Zend_Navigation();
// Replace this section with real dynamic data.
$pages = array(
array(
'label' => 'Save',
'action' => 'save',
),
array(
'label' => 'Delete',
'action' => 'delete',
),
);
// Add pages
$container->addPages($pages);
$this->view->navigation($container);
// Output the data.
echo $this->view->navigation()->sitemap();
Additionally uses Zend Router for redirecting site.com/sitemap.xml to this controller/function.
Thank you for many developers who help me to reach here.
Related
I'm using backpack 3.3 on a laravel 5.5 installation.
I want to prefill two create form fields with two URL passed values.
Say you create a basic backpack crud, named Image.
Normally you can go to domain/admin/image/create to view and fill in the form.
But if I add one or two params in the url, I get a 404.
I guess I should manage the routes file (admin.php)
I tried this way:
Route::group(['prefix' => 'image/{k}/{cid}'], function()
{
CRUD::resource('image', 'ImageCrudController');
});
but still get a 404.
Any suggestions?
Thanks in advance.
Almost all field types have a default option. So when you define them, you can specify a default. And you can always pass a GET parameter for that default. So you can have something like this in your EntityCrudController:
$this->crud->addField[ // Text
'name' => 'title',
'label' => "Title",
'type' => 'text',
'default' => \Request::has('title')?\Request::has('title'):false, // default value
]);
You'd then be able to send you users to yourapp/admin/entity/create?title=your+default+value and have that default value show up in the field.
Hope it helps. Cheers!
it works for me easier
http://127.0.0.1:8000/admin/resultado/create?competencia=2
$this->crud->modifyField("competencia_id",[
'label' => "Competencia",
"default"=>$this->crud->request->query->get('competencia'),
.....
I struggle with getting a form to work in the way I want it to behave.
I have a Regions and Properties model, one region can have many properties and so on...
I created a form to select the Region and then a Property in that region!
The form is having both lists but I struggle to have the second list [Property] updating automagic with only the properties in the region you have selected from the first list [Regions]
When you select a different region in the list, it should update automagic the property list, so you only see the properties for that region! Sorry for my bad explaining, but not sure how to explain this any better.
This is the code in my controller:
// Retrieve the region list
$this->set('regions', $this->Region->find('list', array(
'fields' => array('Region.id', 'Region.regionname'),
'order' => 'regionname',
)));
// Retrieve Property list for the regions.
$this->set('properties', $this->Region->Property->find('list', array(
'conditions' => array('Property.live' => true ),
'fields' => array('Property.id','Property.description'),
'order' => 'id',
)));
This is part of my form.
<?php echo $this->Form->create('Upload', array('action' => 'add', 'type' => 'file')); ?>
<?php echo $this->Form->input('region_id', array('label' => 'Select Region:')); ?>
<?php echo $this->Form->input('property_id', array('label' => 'Select Property:')); ?>
<?php echo $this->Form->file('file'); ?>
I have spend a lot of time looking around here and on youtube, but can't find it :-(
There's no automagic way to do what you're asking. Since all the data for dropdowns have already beed displayed on load, the only way to change the second dropdown depending on the first select is via javascript.
If you search for "dropdown on select" or something similar for cake, you'll find solutions to do it with ajax or plain js. I leave you one reference here. That one is done with ajax and a new action. But you could also do it with just js, doing a find for Regions and Properties and setting them in a json variable in js to be manipulated.
Edit: Accidentally posted uncompleted question.
I need to have a custom form that looks and responds the same as a webforms form.
I have a drupal website which needs a cusotm form to tie into ZOHO CRM (Send leads).
I use webforms for the rest of my site however I am unable to use webforms as I need to customize the action, classes, and IDs of the form to send data to ZOHO.
I want my custom form to look and validate like the webforms forms for consistency. I am unable to implement the same validation.
I have not found a clear and simple article about this yet and it seems so basic perhaps I am over thinking it.
check out Drupal's form API:
http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
if you want you can hook into a webform:
http://api.lullabot.com/group/webform_hooks/7
Use the Form API as tmsimont suggested.
Use
function yourmodule_form(){
$form['search_field'] = array(
'#title' => t(''),
'#type' => 'textfield',
'#size' => '18',
'#default_value' => $form_text,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Buscar'),
);
//then to do your custom validation!
your_module_form_validate(&$form, &$form_state)
{
if(strlen($form_state['values']['search_field'])<3)
{
form_set_error('search_field', t("Search term too small."));
}
}
GOOGLE "JQuery Validate" and look at the examples
I am having a Log-in form and want to add a "Lost Password" Link inside. I found out that you can use the description to do so. But I have now started to change everything to work with routes and would like to use this also for the Forgot Password Link. is there any chance to do this? I can't find a solution, anyone of you who knows how to do it?
$password = new Zend_Form_Element_Password('login_password', array(
'label' => 'Password',
'description' => 'Forgot Password ?',
'required' => true,
));
$password->getDecorator('description')->setOptions(array('escape' => false, 'placement' => 'APPEND'));
I've faced the same problem before, and got answer at
Write hyperlink inside the Zend Form?
May help you also...
When creating a Zend_Form, you don't have access to View_Helpers, as a form does not require a view instance. Therefore you either have to fetch a view in your form's init-method or add the description later (I prefer the latter).
When doing it the first way, you have to fetch the Zend_Controller_Front-instance and then its view, finally call a view helper, e.g. Zend_View_Helper_Url from that view.
The latter can be achieved by adding the description later on, e.g. when you passed the form to your view (or in your controller before passing it to the view):
<?php
$description = '<a href="' . $this->url([...]); . '"'>forgot password?</a>
$this->form->getElement('login_password')->setDescription($description);
echo $this->form;
?>
I think this may be an easy solution, but I've spent an hour now investigating to no avail.
I have a registration form in an element that is being used in views belonging to different controllers. Using the "url" attribute, I've told it to submit to /users/register, but for some reason, the fields aren't submitting to the database.
Instead, there are errors for "undefined index" and a MySQL error for an undefined secondary key that I set (it's empty because it's not being submitted). Strangely, the form works fine if I include the element somewhere in the users views. Does anyone know why this is happening?
UPDATE - Here's the relevant code, sorry:
<?php
echo $form->create(array(
'id' => 'signupform',
'url' => array(
'controller' => 'users',
'action' => 'register')));
?>
The form fields are all correct, since the element works in the user controller's views anywhere. Do I need to include any other information in the creation of the form to point it more directly?
Specify the model 'User' as the first parameter to the $form->create() method.
<?php
echo $form->create('User', array(
'id' => 'signupform',
'url' => array(
'controller' => 'users',
'action' => 'register')
)
);
?>
This will ensure that the form fields are named as data[User][field_name], and prevent you from seeing that undefined index error.
Hope this works for you!
Without seeing the code, it sounds like Cake is magically assuming that the Model is the one for the controller that controls the current view. When that controller is Users, it works correctly. When it is, say, Articles, it will be trying (and failing) to fit the form fields to the Article model.
Without seeing any code, it is impossible to offer any more help.
EDIT:
If the form contains mixed models, e.g. User and Article, you must prefix the fieldnames like this:
$form->input('User.username');
$form->input('Article.title');
etc.
If you don't, the controller will assume they all belong to its own model.