url links in Zend Layout automatically appended by ~username on server - zend-framework

I'm using ZF for my project and my server directory structure is:
/ROOT
__/APPLICATION
__/Zend library
__/public_html(I put all the contents of public folder created by ZF here)
__/docs
__library
I have a single .htaccess file which I put in public_html folder. There are two issues that I want help for.
First,
the url links I'm creating using $this->url(array('controller'=>'home', 'action'=>'index'),null,true), for example, are resulting into <a href='/~wethemen/home'>...</a>, where 'wethemen' is my username on the hosting server account. I checked that in page source. That's why it is not rendering the requested controller and actions as well, may be.
Second,
Only the layout is rendered and no action. My default controller is 'home' so I get this error when I try to access the site.
script:''home'/index.phtml' not found in path (/home1/wethemen/application/views/scripts/).
This is the first time I'm deploying a ZF project on server. Any help will be greatly appreciated. I'll pour the contents of index.php and bootstrap.php if needed.

Just put
$controller = Zend_Controller_Front::getInstance();
$controller->setBaseUrl('/your/base/url');
where you find the text "->setRouter" or anywhere in bootstrap, before dispatch() is called.
Edit: if this does not work and you think it is a HTTP server rewrite issue, adding
RewriteEngine on
RewriteBase /
if you application is accessed at http://yourdomain.com/
or
RewriteEngine on
RewriteBase /your/base/url/
if the application is accessed as http://yourdomain.com/your/base/url/

Related

How facebook like websites is able to load the profile, instead of a directory when a request like facebook.com/profile/username is recieved?

When the facebook.com/profile/{username} is requested how is server able to load page with data corresponding to that user, instead of navigating to a directory named in that {username}, and possibly showing a 404 error ?
It's achieved typically using a pattern called "front controller", where all requests are handled by the same file (let's say index.php, talking specifically about PHP now). So all URLs are like this:
facebook.com/index.php/profile/abc
facebook.com/index.php/account
That file serves as the bootstrap for the application, reading extra parameters (anything after index.php) and dispatching requests to the appropriate handlers/controllers.
Then there's multiple ways you can get rid of that ugly index.php, depending on how you configure your web server (loads of questions here about that subject: htaccess remove index.php from url as an example).
Read more about it here: https://en.m.wikipedia.org/wiki/Front_controller

Redirection in zend framework 1.12 not working

i'm trying to redirect a page to the homepage of the site with some parameters changed. I'm using Zend 1.12 so i set up an action (setAction) inside the controller. The action changes a session variable and should redirect to the referring page. The following is the code of the action:
public function setAction()
{
// if supported locale, add to session
if (Zend_Validate::is($this->getRequest()->getParam('locale'), 'InArray',
array('haystack' => array('en', 'it'))))
{
$session = new Zend_Session_Namespace('ttb.l10n');
$session->locale = $this->getRequest()->getParam('locale');
}
// redirect to requesting URL
$url = $this->getRequest()->getServer('HTTP_REFERER');
$this->redirect($url);
}
This code is not throwing any exception but it is not doing what it is supposed to do, so it's not redirecting to the right page, it is only showing the phpinfo() page, without giving any more clue about what is happening.
Can anyone help?
UPDATE: The file the redirect is showing is the index.php file in the root directory of the server. When i remove it it doesn't show anymore the phpinfo() file but it says index.php not found. But i didn't tell it to render the index.php file. i just redirected it to the home page of the site. any other help is available?
I had to change the .htaccess file as it was set to read the index.php file, so i wrote:
RewriteBase /project/public
It was:
RewriteBase /
But i've noticed that it works even if i comment out the entire line.

Zend Framework deployment to a subdomain

I am using Zend Framework to develop some application. I develop on my localhost and then I upload it to some subdomain like abc.mydomain.com. When I upload my layout index.phtml, I get the following for all URLs:
abc.mydomain.com/css/base.css 404 (Not Found)
on the web browser console but my CSS is in the public folder.
my code to link this css is :
<?php echo $this->headLink()->appendStylesheet('/css/base.css') ?>
What should i do to make these addresses work ?
To complete my question : How does the framework distinguish between a folder and a controller or How could i tell the framework to don't act on these URL ass action , they are folders ?
Sounds like a mapping issue associated to the hosting the subdomain. Often on shared hosting you cannot map the project's public folder to the subdomain. So a variety of rewrite tricks are required to map requests for pages and assets into the right directories without confusing ZF about the requested URL.
Check out:
http://www.papayasoft.com/2010/05/08/zend-framework-shared-hosting/
for a description of the problem and various approaches to solving it.
Usually, the baseUrl() view-helper detects (internally, using the Zend_Controller_Front::getBaseUrl() method) what your app's base-url is.
But sometimes, depending upon your vhost setup and the location of your public folder within the doc root - you need to tell the app explicitly what your base-url is.
In application/configs/applicatiom.ini, you can set:
resources.frontController.baseUrl = "http://abc.mydomain.com"
Then in a view-script, you can access public assets using the baseUrl() view-helper and a relative url (relative to the base you set), as follows:
<?php echo $this->headLink()->appendStylesheet($this->baseUrl('css/base.css')) ?>
though I see many people use it as a prefix-only:
<?php echo $this->headLink()->appendStylesheet($this->baseUrl() . '/css/base.css') ?>

url not found in zend framework though working for index page

i am trying to develop website using zend framework so i had created one index.php file where all my requests goes and c.reated two controller one is IndexController and other is TestController
Class IndexController extends Zend_Controller_Action{
public function indexAction(){
echo "Index Index Jamla";
}
public function displayAction(){
echo "Index Display Jamla";
}
}
now when i access the url http://test/
it correctly calls IndexController and its IndexAction function
but when i access the url http://test/index/index
it displays the message url /index/index was not found on this server same it does when i access http://test/test/index
though http://test/ is equivalent to http://test/index/index
The rewrite rules for Zend Framework are not working.
http://test works because Apache is defaulting to run index.php which will run your application. The router will see no URL parameters so it routes to index controller index action. When you attempt to access anything else, Apache is handling the request and is not rewriting it to index.php so you are getting a 404 not found.
Make sure the .htaccess containing the rewrite rules is in your public folder. Also check that Apache allows processing of .htaccess files for your document root by setting AllowOverride All in httpd.conf and/or httpd-vhosts.conf.
Make sure that you have set AllowOverride to All in your Apache configuration and have enabled the mod_rewrite extension
Silly but can you recheck again either index.phtml file exists under views/scripts/index/

Redirect to same named page in directory structure before path changes

Well, say I have a number of html pages in my web. The case is that I´m doing changes sometimes in the directory structure, so when anybody try to access to a determinated URL, it's possible that such URL does not exit. The files names don't change but so do the paths.
As far as I now, the server takes the user to a "404" page that can be customized. Is possible to customize the page in this way?:
The user tries oneweb.com/oldpath/page.html; which does not exist.
A 404 customized page is launched
404 page runs an script IS THIS POSSIBLE?
The script is given the name of the file WHERE IS STORED SUCH NAME?
The script search the entire directory structure to find page.html HOW TO ACCESS TO THE STRUCTURE
The file is found and the new URL is stored: oneweb.com/newpath/page.html
a link appears showing the new URL
Maybe this process is relatively common and I can find some related code or tutorial?
Are you using Apache? Linux?
Add a 404 handler
ErrorDocument 404 /404.php
Then use 404.php to parse the url. This simple example just grabs everything after the last / in the URI so http://example.com/foo/bar/page.html would put page.html in $url:
$url = end(explode('/', $_SERVER['REQUEST_URI']));
Then use one of the comment example functions in http://php.net/manual/en/function.readdir.php to search your directory and find the file.
Then do a header 301 redirect
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://example.com/' . $file_path);