Zend framework redirector doesn't work properly - zend-framework

I'm trying to develop a site using Zend Framework, but i have a problem:
I have the default controller which shows me a page with a link. That link uses another controller and redirects me to a start page from that controller (i have implemented startAction() in my custom controller, and the start.phtml page in the modules/default/view/scripts/disc directory).The start view contains a table which is populated from a database, and three link: Add, Edit and Delete. For the Add link i use in start.phtml the following code:
<p>Add</p>
And for the other two link something like that except the action name. First time when i use one of the links, everything works fine, but when it returns me to the start page all the links don't work anymore. They just keep me in the start page. In my addAction() i do the things i need, and at the end i use the following code to return to start page :
$this->_helper->redirector ( 'start' );
and when the start page is loaded again the 'Add' link points to the start page and not anymore to the Add page. The same thing happens with the other two links.
Can anyone help me, please ?

you are attempting to use the short hand version of the action helper Redirector()
$this->_helper->redirector ( 'start' );
To avoid confusion with the utility method version (and because I don't know what the exact defaults are) I always use the proper form.
//the redirector helper has to many options to comfortably short hand.
//gotoSimple(), gotoUrl() and gotoRoute() are all easy to use.
$this->_helper->getHelper('Redirector')->gotoSimple('action' => 'start', 'controller' => 'index')
to use the utility method _redirect(), try something like this (it acepts a url):
$this->_redirect('/index/start');

I think that start must be its own route. As a result, you need to specify the default route when using the url view helper:
In start.phtml, try this:
<p><a href="<?php echo $this->url(
array ('controller' => 'disc','action' => 'add'), 'default');
?>">Add</a></p>

Related

click_no_wait and then execute_script

I'm using the page object gem with a page that contains a link.
When the link is clicked, the browser navigates to a new page, and the HTML renders as expected.
However, my script is always returning a Timeout::Error: Timeout::Error. After looking at the browser network activity, I noticed a pattern with a long running get that never completes.
If I run the script and then go to the console and issue the command
$.connection.hub.stop(), the script will not time out.
Is there a way to perform a click_no_wait or to click and then execute a script via the use of page_object_gem ?
Here is my page-object attempt, but it is resulting in a timeout still.
class MyThing
include PageObject
include PageObject::PageFactory
link(:show_details, :id => 'detailLink')
def click_show_details_no_wait
begin
show_details_element.click
rescue Exception => e
execute_script('$.connection.hub.stop();')
end
end
end
It is hard to suggest without your page. My first idea is to try to do
show_details_element.fire_event('click')
instead of a usual click.
The second idea is take a look at
Stop loading page watir-webdriver
Is there have method to stop page loading in watir-webdriver
how to click on browser “stop loading this page” using ruby watir?
Good luck.

Drupal 7 some non-existing URLs are not Redirecting to 404?

In Drupal 7, some of (non-existing) URLs are not redirecting to 404 or any error page it should. Instead, it still remains showing its Top Parent Folder. For example like:
www.mywebsite.com/items/aaaaaaaaaaaaa
www.mywebsite.com/items/bbbbbbbbbbbbbbbbbb
Every WRONG URLs under /items/ i put like above, are showing the Page of its parent:
www.mywebsite.com/items instead of get redirected to 404
I don't want its parent to be shown if there is no page really.
But the strange thing is, it is NOT happening on every patterns. I mean, another different parents like:
www.mywebsite.com/users/aaaaaaaaaaaaa
www.mywebsite.com/users/bbbbbbbbbbbbbbbbb
For the wrong url typed-in under this /users/ parent path, it is CORRECTLY redirecting to the 404 page.
What is it please?
If I understand your question correctly, it's not a problem at all.
That's because how your/contributed/core modules hooks Drupal menu system.
If a menu item (menu router item to be specific. Think about a path like "admin/config/development/performance") has no "%" sign in it, menu callback function will be executed.
For an example, if a module registers "items" path example.com/items path would not be a 404, and the appropriate menu callback function of the menu item will be fired. That callback function can make use of further URL parts (example.com/items/123) if given.
'node' is a good example. (technically they are different menu router items though) .
Opening example.com/node will not fire a 404.
If a module registers 'items/%' , then, example.com/items will fire a 404. In other words, the second URL part is required in order to execute the menu callback function.
If the problem you are facing is related to a custom module, make sure you register the correct version of your router items. If the second URL part is required, register items/%.
You can execute a 404 by calling drupal_not_found().
Look at this, really helpfull
http://peterpetrik.com/blog/2009/11/non-existent-urls-views-2
Are you using Views for that path (/items)?
Here is an issue for Views: Prevent duplicate content (because Views returns 200 instead of 400 404)
You could create a Contextual filter to prevent this.
merlinofchaos wrote:
If you don't want this behavior, add the Global: NULL argument to Views and use the setting to validate that the argument is empty.
For Drupal 6, the module Views 404 might help.
You can configure your drupal installation to redirect to a specefic 404 page that you create..
Go to www.yoursite.com/admin/config/system/site-information and enter your 404 page .

How to hide one particular controller name in URL in Zend Framework

I have a site in Zend Framework. I want to hide one particular controller name in the URL. Explaining the requirement below.
Current URL: http://abcd.com/user/john (which is a profile page of a user)
Preferred URL: http://abcd.com/john
The preferred URL will be displayed in the browser. Also, if a visitor types a username (for eg. http://abcd.com/smith) in the url, the browser will display the user profile.
I have some other controller as well in my site (for eg. http://abcd.com/registration) and don't want to modify or hide those controller name.
I know this can be toodifficult to make a difference to recognise which is the username and which is the controller in the url, but i really want to accomplish this. Please suggest me the needful.
Please note that i am using the below html code to display user profile link.
John
Also added the below mentioned router in bootstrap.php file.
$routeUser = new Zend_Controller_Router_Route ('user/:username/',array('controller' => 'User','action'=> 'index'));
$router->addRoute('user', $routeUser);
Routes are checked in reverse order, so you can change user route to be just :username but then the router has no way of knowing that example.com/registration is not a user profile, which is why this would break your other route. The easiest way to fix this would be to add another route after the user route which handles the registration request:
$router->addRoute('registration',
new Zend_Controller_Router_Route('registration/:action', array(
'module' => 'default',
'controller' => 'registration',
'action' => 'index'
))
);
Alternatively if you are fairly comfortable with ZF and want to handle the user requests properly without breaking the standard routes, you could create a custom route class specifically for your user profile requests. I wrote up a blog post a while ago on how to do this, see: http://tfountain.co.uk/blog/2010/9/9/vanity-urls-zend-framework

form_helper doubling action in CodeIgniter

I am currently taking tutorials on how to use CodeIgniter and am taking a tutorial to create a simple newsletter. For some reason when I hit the submit button a 404 page not found error is created and its obvious because the url doubles. Meaning, the url is:
www.my_site.dev/index.php/email
and when I hit the submit button is should be:
www.my_site.dev/index.php/email/send
but it doubles the url like this:
www.my_site.dev/index.php/www.my_site.dev/index.php/email/send
I am using the form helper:
$autoload['helper'] = array('url', 'form');
I just can't figure out where in the autoload or config files how to troubleshoot the reason for this or what to set to make the action appropriate.
To clear up any confusion HERE is my view and controller.
Adding http:// to base_url is a start, but is base_url set to http://example.com/ or http://example.com/index.php ? (the latter one is incorrect)

Can I integrate a Zend-Framework powered web application into a wordpress site?

I have a project in which I want to be able to call wp_list_pages() on a page that also uses the Zend Framework to power some complex interfaces manages custom data outside of wordpress.
This page should also redirect the user to the wordpress login screen if they're not already logged in with the appropriate level of authorization.
How would this work at a high level, i.e. do I need to edit the wordpress bootstrap file to conditionally implement the custom interface based on a specific URL or something, but still include certain files to be able to call wp_list_pages() on that custom interface?
I've developed a couple of WordPress plugins, and I've found it's really easy to extend. Haven't worked with Zend though.
You should check the WordPress plugin api. Mostly the part about actions, filters and hooks: http://codex.wordpress.org/Plugin_API
You can even override some functions (not sure if wp_list_pages() is overridable).
It's pretty well documented, and there's a large developer community behind it on IRC, forums, etc.
Thanks Fernando.
I just read this thread which suggests that you can use Zend in any script by just including:
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
So given that all I need to use Zend for is on one page, can I just include that code in a custom template file that I assign to the appropriate page in the navigation? If I used javascript to submit the form via XHR, the requested URL would take the form '/controller/action' - but Zend wouldn't know the controller directory.
Could I put Zend code into the wordpress bootstrap, i.e. the above code plus the frontController configuration, and then use Zend wherever however?
So I've created a page in Wordpress and a custom template for that page, in which I've placed the following Zend Framework code:
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'dbname' => 'dbname'
));
Zend_Db_Table::setDefaultAdapter($db);
class Users extends Zend_Db_Table_Abstract {
protected $_name = 'wp_users';
}
$users = new Users();
$users = $users->fetchAll()->toArray();
print_r($users[0]['user_login']);
This all works fine, so it's clearly possible to use Zend in conjuction with Wordpress at least to some extent.
It's becoming apparant that the problem is about who controls the URL rewriting, or the routing, or the bootstrapping (not sure of the correct terminology). If I were to put the end of the above code, starting $users = new Users();, into a controller as follows:
class UsersController extends Zend_Controller_Action {
function getUserAction() {
$this->_helper->viewRenderer->setNoRender();
$users = new Users();
$users = $users->fetchAll()->toArray();
echo $users[0]['user_login'];
}
}
How would I then call that function? My intention would be to call it from javascript via an XHR request in response to an event on the page, but requesting the URL 'index.php/Users/getUser/' returns 'No input file selected'. Trying to access the URL http://www.domain.com/Users/getUser/ produces a Wordpress 404 page.
Is there a way around this? It doesn't just apply to wordpress, of course - I expect it applies to any existing application that rewrites/routes requests via a bootstrap.
I guess you could do that, just import the framework into the one page you need it for. I don't know how Zend works, but check the paths as to where to put your directories so that Zend finds them.As I said I guess you could do that, just experiment and tell us how it went!
Beware of name conflicts for functions and/or variables, this shouldn't be much of a problem coming from such popular products as WordPress and Zend though... (which should be theoretically well coded)
I guess you could do that, just import the framework into the one page you need it for. I don't know how Zend works, but check the paths as to where to put your directories so that Zend finds them.As I said I guess you could do that, just experiment and tell us how it went!
Beware of name conflicts for functions and/or variables, this shouldn't be much of a problem coming from such popular products as WordPress and Zend though... (which should be theoretically well coded)
I've built a plugin for wordpress that has a similar goal to yours, more modeled on CodeIgniter though. Not knowing Zend terribly well, I think this should help:
Make a file named routes.php in your plugins directory with the following code:
add_action( 'init', 'add_custom_urls' );
function add_custom_urls(){
global $wp, $wp_rewrite;
$wp_rewrite->add_rule( '(.*)$', 'index.php?&cPath=$matches[1]', 'top' );
$wp->add_query_var( 'cPath' );
}
Be sure to activate both plugins in your admin. These two files will allow you to catch the url before Wordpress tries to figure out what to do with it. You can use regular expressions to have finer control over which pages to catch. You may have to delete the record in your _options db table where option_name = 'rewrite_rules' before this works.
Next, make another plugin with the following code:
add_action( 'template_redirect', 'bootstrap' );
function bootstrap(){
global $cPath;
echo( "cPath : $cPath" );
if( $cPath ){
dosomethingwith( $cPath );
}
}
Put all your code in the dosomethingwith() function. You'll need to figure out if the url requested can me mapped to a zend controller, etc. http://www.domain.com/Users/getUser/ would give you $cPath = Users/getUser/ If successful, you'll also probably want to die(), so once it is completed Wordpress won't try and take over again.