Redirection from module to application - zend-framework

how can we go back form one module to parent application in ZEND. I use this code:-
<?php echo $this->url(array('controller' => '', 'action' => '')); ?>

If you add a 'module' key to the URL array, you can easily traverse modules. If you're trying to get to the "Parent" (the default module, perhaps?), you'd change your code to:
<?php echo $this->url(array('module' => 'default', 'controller' => 'index', 'action' => 'index)); ?>

Related

Cakephp2 post to plugin controller

Having hard time figuring out how to post a form to a plugin controller.
Say I have a reg/login plugin that could be shared with different apps.
in reg.ctp:
echo $this->Form->create(null, array('url'=>array('controller' => 'user', 'action' => 'submit','plugin'=>'user')));
I get missing controller.. in app/controller/user.php
what did do wrong?
Looks like your controller is not pluralised. All controllers in Cake, by convention, are plurals.
array('controller' => 'users', 'action' => 'submit', 'plugin' => 'user');
Should route to
app/Plugin/User/Controller/UsersController::submit()

Display boolean as radio button in CakePHP form

Does anyone know how to display two radio buttons in a form in CakePHP and have them save to a boolean field in the DB?
I can get my boolean value to display as a checkbox (default behaviour) but I need to display two radio buttons, however when I do this the changes don't get saved to the DB.
I feel like it's something very simple. Here's my code:
<h1>Edit Content</h1>
<?php
$thisVal = $this->data['LessonContent']['is_exercise'] ? "1" : "0";
$options = array(
'0' => 'Learning Material',
'1' => 'Exercise'
);
echo $this->Form->create('LessonContent', array('action'=>'edit'));
echo $this->Form->input('name', array('label' => 'Name'));
echo $this->Form->input('description', array('label' => 'Description'));
echo $this->Form->input('is_exercise', array(
'type' => 'radio',
'class' => 'radio',
'legend' => false,
'name' => 'Type',
'options' => $options,
'value' => $thisVal
));
echo $this->Form->input('id', array('type'=>'hidden'));
echo $this->Form->input('lesson_id', array('type'=>'hidden'));
echo $this->Form->end('Save Content');
echo $this->Html->link('Cancel', array('controller'=>'Lessons', 'action'=>'view', $this->data['Lesson']['id']));
?>
Thanks
You're overriding the name of the input, therefore the value for is_excercise will be sent as Type.
Remove the name option;
echo $this->Form->input('is_exercise', array(
'type' => 'radio',
'class' => 'radio',
'legend' => false,
'options' => $options,
'value' => $thisVal
));
note after making this change, you probably don't even have to manually set the value of the radio-button.
debugging
In situations like this, always check/debug the posted form-data, either via FireBug or by debugging it in CakePHP, by putting this in your controller;
debug($this->request);
Even better, install the CakePHP DebugKit Plugin this plugin shows all the information (request data, queries, session variables etc.) without having to add debug-lines

Cakephp form creation gives me missing database table

According to the manual, I should be able to do this which is to leave Model as null
<?php
echo $this->Form->create(null, array('url' => '/recipes/add'));
// or
echo $this->Form->create(null, array(
'url' => array('controller' => 'recipes', 'action' => 'add')
));
But in reality, I got error saying missing database table? Why?
I have my Model which is not directly mapping to any table. Why can't I leave it as null? Something like this:
<?php echo $this->Form->create(null,array('url' => array('my_account','action' => 'change_avatar'),'type' => 'file'));?>
Try passing false for the model instead of null:
<?php
echo $this->Form->create(false, array('url' => '/recipes/add'));
// or
echo $this->Form->create(false, array(
'url' => array('controller' => 'recipes', 'action' => 'add')
));
From the manual:
You can also pass false for $model. This will place your form data into the array: $this->request->data (instead of in the sub-array: $this->request->data['Model']). This can be handy for short forms that may not represent anything in your database.
make a table with name recipes in your database. The submitted date from the form will be saved at recipes table.

CakePHP - Best way to customise form action?

I have a search form, which uses a Search controller/model.
echo $this->Form->create('Search', array('action' => 'query', 'type' => 'get'));
...
echo $this->Form->end();
But by default the form submits to '/searches/query'. How do I get the URL of the search page to be /search/query instead?
I don't really want to use .htaccess rewrites if possible, as that seems kind of messy. Hoping there is a tidy Cake way of doing this.
I think this could be done with a custom Inflector rule in bootstrap.php maybe, but I'm not sure how.
Just use the router. In your routes file, add:
Router::connect('/search/:action/*', array('controller' => 'searches'));
Router::connect('/search/*', array('controller' => 'searches', 'action' => 'index'));
Read more about the router in the book.
Isn't there a way to say:
echo $this->Form->create('Search', array('action' => 'search/query', 'type' => 'get'));
And then setting up a router for this?
$this->Router->('search/query', array('controller' => 'searches', 'action' => 'query'));

Zend Framework: Routing seems to interfere with rendering of Zend_Navigation menu

i have setup a route like below in bootstrap.php
$route = new Zend_Controller_Router_Route(
'users/:id',
array(
'controller' => 'users',
'action' => 'view'
)
);
$router->addRoute('viewUser', $route);
when i try to goto /users/1, and in view script do echo $page->getHref(), i get
Fatal error:
Zend_Controller_Router_Exception: id
is not specified in
D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\View\Helper\Navigation\HelperAbstract.php
on line 522
when i try to goto /users/view/id/1 it works ok. i am wondering why would rendering menu items from Zend_Navigation crash in something separate like routing?
ok i solved the problem with help from another post
basically, i need to add a default value for id
$route = new Zend_Controller_Router_Route(
'users/:id',
array(
'controller' => 'users',
'action' => 'view',
'id' => '0'
)
);
$router->addRoute('viewUser', $route);