ZF controllers redirecting to index controller - php

I had set up a zend framework project.My index controller working fine. But when i tried to access other controllers, i m getting content of index controller only.
For example when i access user/signup, in url i m getting same user/signup, but it taking actions from index controller only.

check your pluggings. search setController(), setAction() methods in your project. When you use that methods they never change URL. But show content for that.

Related

Routing in CodeIgniter for (:any)

I'm trying to make my CodeIgniter application work similarly to WordPress.
I want to be able to make these kind of URLs:
http://www.example.com/my-post-example
http://www.example.com/new-headline-here
http://www.example.com/i-love-stackoverflow
My routing:
$route['(:any)'] = "core/index/$1";
Which will call my Core controller and pass the page name into the index function.
I then lookup in my database for the page name and display the page to the user. So far so good.
However, there will be times when I want to call another controller. For example:
http://www.example.com/admin/edit_page/3
http://www.example.com/admin/settings
Now I assume my route will just grab all these rules and send them into my Core controller. Is there a way to make an exception for certain pages? Or is it a good idea to do this check inside my Core controller.
For example,
if ($page not in DB) {
// Call controller/method
}
This seems a little redundant since I just want CodeIgniter to handle this.
The routing rule you using it is OK for your purpose.
If you use http://www.example.com/admin/edit_page/3 this link it will send you admin controller and edit_page method.It will not use routes any rule.
However you will get one problem if your link looks like this
http://www.example.com/my-post-example/test
It will try to go my-post-example controller and test method.
Again http://www.example.com/admin will use routes any rule, means it will redirect your to core controller instead of admin/index. In that case your url should be http://www.example.com/admin/index
Finally If you call your other link with controller/method name it will be OK using your any rule

Codeigniter: Index page creation

My folder structure is as following
admin
__master
_______address_book
_______Users
_______Product
_______etc
__operations
_______register_orders
_______payments
_______etc
I have created controllers for address_book,users,products,register_orders, payments etc to reduce the complexity of each controller.
Now, how to handle index page request for www.abc.com/admin ?
I have created Admin controller in /controllers directory then other links like
www.abc.com/admin/master/address_book will not work.
How to handle both requests?
I would also like to know is there any way to handle each index page requests
eg:
www.abc.com/admin/
www.abc.com/admin/master/
www.abc.com/admin/operations/
To access each request with url like-
www.abc.com/admin/
www.abc.com/admin/master/
www.abc.com/admin/operations/
you have to use codeigniter's routing. And for routing there are a config file under aplication/config folder named routes.php. Add all your routes in this file. Suppose you want to access this url-
www.abc.com/admin/operations/
then you have to create a new route for this in the route file, like-
$route['admin/operations'] = 'admin/operations';
where in $route array index you have to mention what will be the url and the value against this index you have to mention the controller's path and also you can mention the controller's function name which will be invoked (for index function there no need for mentioning).

Blank page - phalconphp

Can you tell me, why when i trying add new action to ex. AboutController in clear invo example, get blank page after if I enter to site/about/blabla? In PhalconPHP framework.
See http://docs.phalconphp.com/en/latest/reference/routing.html
If you are using default routes from phalcon with yoursite.tld/controllerName/actionName/params then you should have create the controller with said name and the action inside it.
So for your example, if you said you are using the invo example, the url site/about/blabla is valid only if your controller class is called siteController, inside you have the public method aboutAction wich take on parameter that will have the value 'blablabla'.
But if you have you app in an subfolder of you document root, called site, the all the explanation before this shifts one position to the left.. aboutController and blablaAction.
You also might want to add your controller/action pair int the ACL in app/plugins/SecurityPlugin.php

Removing controller name and function namein URL in Codeigniter CMS

I am building a cms in codeigniter and i want to remove controller name and function name form the url and just print the alias.
I will be having two controllers one for static pages and other for blog posts with categories.
Please help, Suggestions reagrding modification of two controllers are also welcome.
You will need to override the default 404 controller in application/config/routes.php.
$route['404_override'] = 'content';
Any request that can't be mapped to a controller will be passed to the application/controllers/content.php controller
Your Content controller, or whatever you decide to call it, will parse the uri [$this->uri->segment(1)] and check for a matching reference in your CMS database.
If there is no match in the database, then you can look for a static view in the views folder and load it.
if(is_file(FCPATH.'views/'.$this->uri->segment(1).'.php')) {
$this->load->view($controller,$this->data);
}
If no static view is found, and there is no matching content in the db, call the show_404() function.
Using this method, you will keep the default CI functionality of uri mapping, so at any time, you can add controllers as you normally would and the app will perform like a vanilla CI install.

Why ZendFramework $this->getFrontController()->getBaseUrl() is returning empty string inside a controller?

I'm using ZendFramework 1.11.11 for my application and I need know the URL (more specifically the path) that fire up my controller inside my controller.
When I try
$this->getFrontController()->getBaseUrl();
an empty string is returned. I test that code with the default application created by ZendStudio and accessing it typing http://test.com/default/index/index and nothing.
Any idea how get the URL that fireup a controller inside the controller?
The base url is the offset from the original slash that you've set up in your configuration. You do not have a base url, as default is the name of the module, index is the controller, and index is the action.
For firing up another controller, check out this link http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.utilmethods
To get the current path in a Zend fashion from a controller, do the following.
$this->getRequest()->getPathInfo();

Categories