Zend Framework Redirect and Routes, somehow not working - zend-framework

I've been trying to wrap my head around routing and for that very reason build a small aplication to fiddle around with, but i've managed to stumble upon a problem.
The goal of the whole test was to hide the url 'hostname/content/index/add' and turn it into a url more understandable for a user like 'hostname/wms/content/add'.
But now for some odd reason i cannot redirect using the $this->url() methode. But somehow a normal link like somelink work.
I have build a few routes in the application.ini to test how it works. It's nothing fancy...
resources.router.routes.contentroute.route = "/wms/content"
resources.router.routes.contentroute.defaults.module = content
resources.router.routes.contentroute.defaults.controller = index
resources.router.routes.contentroute.defaults.action = index
resources.router.routes.vacaturesroute.route = "/wms/vacatures"
resources.router.routes.vacaturesroute.defaults.module = vacatures
resources.router.routes.vacaturesroute.defaults.controller = index
resources.router.routes.vacaturesroute.defaults.action = index
So when i type hostname/wms/content i get redirected to the content module's IndexController and it's IndexAction. This works fine for all the links in my views that point to the content module like this
<a href='wms/content/'> link </a>
However it's not working for 3 links that actually redirect towards a specific action of the IndexController on that very page hostname/wms/content.
Add new content
Instead of actually redirecting towards the add action in the IndexController i get redirected to hostname/wms/content, wich is the page i'm comming from.
Anyone have an idea why this is happening and possibly a way to solve this? Or am i totally approaching this the wrong way?

First, your route are static ones. You should replace them with:
resources.router.routes.contentroute.route = "/wms/content/:action/*"
resources.router.routes.contentroute.defaults.module = content
resources.router.routes.contentroute.defaults.controller = index
resources.router.routes.contentroute.defaults.action = index
Then, you should specify the name of your route and pass true in reset argument:
$this->url(
array('module'=>'content', 'controller'=>'index','action'=>'add'),
'contentroute',
true
);

try this instead
Add new content
Replace xyz with your module name.

Related

How do I use Perl's Remote::Selenium::WebElement to verify the URL a hyperlink will take me to?

Seems like it should be straightforward but I can't seem to get to the bottom of it.
Here's the HTML I'm working with:
<li id="a" class="FILElevel3" onclick="changeMenu("b")">
<a onclick="stopBubble(event);" href="javascript:LinkPopup('/sub/URL.html')">Visible Text</a>
I'm able to find the element using XPaths:
my $returned_asset = $sel->find_element("//*[\#class='LINKlevel3']");
And I can verify this works because I'm able to extract the visible text from it:
my $returned_name = Selenium::Remote::WebElement::get_text($returned_asset);
I just can't seem to find the sequence to pull the HREF attribute from the element to put the link's URL into a verifiable string. Should I be able to do this using WebElement's get_attribute() method? I've tried variations on this:
my $returned_URL = $returned_asset-> Selenium::Remote::WebElement::get_attribute("a/href");
...where I've plugged in everything I could think of for that "a/href" string. What should go in there?
In the end I'd like to be able to put "javascript:LinkPopup('/sub/URL.html')" into a string and verify that my URL is in there.
have you tried
my $returned_asset = $sel->find_element("//*[\#class='LINKlevel3']/a");
my $returned_URL = $returned_asset->Selenium::Remote::WebElement::get_attribute("href");

Zend Framework: Dynamic content based on Pincodes / Zipcodes

This seems like a challenge to me! I need to display dynamic content for different pincodes / zipcodes. So the way zend works with url is controller/action if i am not wrong!
Usually user will be selecting the pincodes / zipcodes by clicking on the anchor tag. So how do i create the logic to implement this. Obviously creating different pincode / zipcode controllers and actions and respective views is a bad idea.
what is the best way you would recommend me? Please forgive me if its unclear. I will try to give more info if needed.
Thanks.
You might pass the pincodes/zipcodes in the URL as parameters to your action. For instance, you could have something like:
12345
And then, inside your controller, you can get the value of the parameter like that:
public function youractionAction()
{
$zipcode = $this->_getParam('zipcode', '');
//
// Generate the dynamic content based on the value of the zip code...
//
}
Hope that helps,

Zend creating forms based on requests within one controller/action

I don't really know how to word the title well, but here's my issue. I decided instead of having 25 controllers to handle pages, I have one PageController with a viewAction that takes in a :page parameter - for example, http://localhost/website/page/about-us would direct to PageController::viewAction() with a parameter of page = about-us. All of the pages are stored in a templates folder, so the viewrenderer is set to render application\templates\default\about-us.phtml.
I did this so I can consolidate and it seemed like a better approach. My question is the following: lets say when the page request is contact-us, I would need a Zend_Form to be used within the contact page. So, I would need a way within PageController::viewAction() to recognize that the page needs to have a form built, build the form, and also upon submission the need to process it (maybe this should be handled in an abstract process method - not sure).
I have no idea how to implement this. I thought maybe I can store a column with the name of a form and a connecting page identifier. Even better, create a one-to-many page to forms, and then in the submission loop through the forms and check if submitted and if so then process it (maybe there is a isSubmitted() method within zend_form. I really don't know how to handle this, and am looking for any help i can get.
Thanks!
Here is something that came to mind that may work or help point you in a direction that works for you.
This may only work well assuming you were to have no more than one form per page, if you need more than one form on a page, you would have to do something beyond this automatic form handling.
Create a standard location for forms that are attached to pages (e.g. application/forms/page). This is where the automatic forms associated with pages will be kept.
In your viewAction, you could take advantage of the autoloader to see if a form for that page exists. For example:
$page = $this->getParam('page');
$page = ucfirst(preg_replace('/-(\w)/ie', "strtoupper('$1')", $page)); // contact-us -> ContactUs
$class = 'Application_Form_Page_' . $page;
// class_exists will invoke the autoloader to map a class to a file
if (class_exists($class)) {
// a form is defined for this page
$form = new $class();
// check if form was posted
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()->getPost()) {
// form is valid - determine how to process it
}
}
// assign the form to the view
$this->view->pageForm = $form;
}
All this really leaves out is the action you take to process a specific form. Since the contact form will likely generate an email, and another form may insert data into a database, you will need some sort of callback system or perhaps another class that can be mapped automatically which contains the form processor code.
Anyway something along those lines is what came to mind first, I hope that helps give you some more ideas.

Drupal, overriding add/edit form forms for custom content type

I have created a new content type called protocol. The problem is that when you define a content type that means you also say how in the form the content is to be added and edited, like which form elements there will be.
A protocol is a content type that stores a title, an abstract and instructions. I want to add the title/instructions/abstract through one textarea where you tag the parts of the text like this:
[title]This is a title[/title] [abstract]This is an abstract. [/abstract][instructions]And these are my instructions.[/instructions]
That text is then processed and the content between each tag can be picked out and stored in a variable which should then be stored for the content type just like it had been added through a seperate field/textarea in a add/edit content form.
Is this possible to do? What kind of things should I read up on? Where in the drupal code are the function/functions that describes what happens when you push "Save" for a new content type for the standard add content form?(I just want to read it, not change anything)
Not sure this exactly matches what you're trying to do, but in a basic sense it should get you towards your goal. I wrote a module called endorse for Drupal 6 that provides a custom form feeding the submitted values into a new node:
http://drupal.org/project/endorse
Here's the form definition:
http://drupalcode.org/project/endorse.git/blob/refs/heads/master:/endorse.module#l136
Some basic validation follows and then the actual node save occurs at the top of the submit function, here up to line 231:
http://drupalcode.org/project/endorse.git/blob/refs/heads/master:/endorse.module#l206
The rest in that function is irrelevant except for the thank you and redirect at the very end of the submit function. If you're doing this in D7, it'll change a bit (see api.drupal.org for function definitions and whatnot), but it should look more or les the same.
Steps to solve your problem.
Create a module. Implement hook_menu with your custom add page.
Create a custom form using FORM API that it's gonna be displayed in your new page.
In your hook_form_submit get your values from the variable form state.
Parse the text and create and save a new node (snippet here).
$newNode = (object) NULL;
$newNode->type = 'protocol';
$newNode->title = $parsed_title;
$newNode->uid = 1;
$newNode->created = strtotime("now");
$newNode->changed = strtotime("now");
$newNode->status = 1;
$newNode->comment = 0;
$newNode->promote = 0;
$newNode->moderate = 0;
$newNode->sticky = 0;
// add CCK field data
$newNode->field_{YOUR_CUSTOM_FIELD_1}[0]['value'] = $parsed_data1;
$newNode->field_{YOUR_CUSTOM_FIELD_2}[0]['value'] = $parsed_data2;
// save node
node_save($newNode);
Those are the basic steps. If you have any more questions please ask.
TIP: Install the Devel module and use the function dpm() when you need to know the contents of some variable. You are probably gonna need it when you are implementing hook_form_validate or hook_form_submit for knowing the contents in the variable $form_state.
So just do:
dpm($form_state); //this will give you the variables inside the array with a krumo view.

GWT - Create a link to external website

I need to create a link that point to another website, not to the portal itself trought ajax call. I write this at the moment :
InlineLabel fv1=new InlineLabel("Validator W3C : ");
InlineHyperlink linkfv1 = new InlineHyperlink("HTML" , "http://validator.w3.org/");
InlineLabel fv2=new InlineLabel(" | ");
InlineHyperlink linkfv2 = new InlineHyperlink("CSS" , "http://jigsaw.w3.org/");
but it call the portal. In fact, if i click on HTML it adds #http://validator.w3.org/ in the navigation bar. How can I fix this? Bye
The docs for InlineLabel say that it's meant to be used for "internal" links -- i.e., only to change the part after the #, like you're seeing.
You want to use Anchor -- this will result in an <a> tag being added to your page.
I prefer this solution:
Define an object of HTML class with the necessary parameters then add that object to a container in your GWT interface, FlowPanel for instance.
HTML link = new HTML("Take me to stackoverflow");
flowPanel.add(link);