I want to manage my url in codeigniter...
where my frontend should be like this
"http://www.Himalayi.com/" and the
admin panel should be http://www.Himalayi.com/__admin
I am not able to manage though i've tried alot..
the folder structure is given below
Please
Help me.. Thanks
application/
controller/admin/home_banner.php,user.php
model/admin/model_home_banner.php, model_user.php
view/admin/home_banner/add.php
and
in the same folder controller i have
frontend folder the file is welcome.php!
how to manage in config, routes, htaccess
I do not know why you would want to prepend underscores to access the admin panel. Please keep in mind that defining controller functions like:
public function _notReachable(){
#do something
}
will result in an inaccessible function regarding web requests.
So calling example.com/home/_notReachable will not work.
Maybe that already solves your problem?
See codeigniter documentation "Controllers - private Functions".
Related
Ok, guys, this is the case...
I am working in an old porject made it with CodeIgniter v2 (currently all is in localhost). For new features I created a folder called v1 inside the api folder
The structure of the project:
controllers
api
v1
visit.php
orders.php
controller1.php
controller2.php
The problem is that I can not access to the visit.php controller
to test purposes I set the visit controller in the api folder an access it whit this:
localhost/projectname/index.php/api/visit/visits
visits is the function in the visit controller
With this way everything works!! but, when I set the visit controller in the v1 folder I get a 404 page not found error.
localhost/projectname/index.php/api/v1/visit/visits
Extra
Another think that have keep in mind is. This project is using a library to the REST API so, in the visit controller are tho functions
public function visits_get(){
// return an arrays of visits
}
public function visits_post(){
// to add a new visit in a bd
}
So, the function will be called depends on the request method
I have been reading and I found that I have to configure the route.php, actually I did it but without success.
Thanks and I hope you understand what I am asking!
ROUTE.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "welcome";
$route['404_override'] = '';
This is all that the route.php has in it ._.
To my knowledge, any controllers falling outside the application/controllers/controller_name.php naming convention need to be explicitly defined inside the routes.php file, otherwise CI will not look inside subfolders. It's not much of a problem, actually, add something like this for your controllers:
//You'll need to do this for all of your API controllers, unfortunately
$route['api/v1/(:any)'] = 'api/v1/$1';
//If you have controllers taking arguments, eg. /api/v1/stuff/1
$route['api/v1/(:any)/(:any)'] = 'api/v1/$1/$2';
//Catch-all route for 404's, recommended
$route['api/(:any)'] = 'api/v1/error_api';
Have a look at the routing docs for CodeIgniter 2 for more info.
I would like to add a new phtml file to my index folder in which I already have several views:
index
landing
And so on... I access them by using the following logic:
sitename.com/index/landing
or
sitename.com/index/index
How can I add the phtml file (my new view) to my index folder so that I'm able to see it when I enter in the browser:
sitename.com/index/mynewview
I'm quite new to the whole Zend Framework, and I'm not sure how the structure works exactly, so I'd like to find out more. Can you guys help me out with this, how am I supposed to do this?
Thanks heaps! :)
P.S. The views are in the following directory structure:
module/application/view/application/index/
and then here are all of the views, this is where I'd like to add my new view and access it from browser like this:
/index/testview
Edit:
When I add the testview.phtml to the index directory and put some test tags like this in it:
<h1> Testing new view page </h1>
It's not being rendered on the browser
Because this is an MVC framework, you're skipping a few steps. You're probably going to get a few harsh responses, but I'll try to fill in the holes for you very quickly.
Ignore the file folder structure for a minute.
This is a route:
/index/landing
Routes point to Actions inside of Controllers to work.
Assuming you have started with the skeleton, open up your module's module.config.php, you should see route config, e.g.:
https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php#L29
You'll need to add a config entry for the routes you want to serve. It could be as simple as a Literal entry for /index/landing, or something more complex (Segments, Regex, etc.) that handle patterns for routing. Spend some time tinkering and learning here; routes are pretty critical to working with MVC.
When configuring the route, the assumption is that you have a Controller set up, and that this Controller has an Action (to which your route is pointed). That Action, is where you can connect template files (phtml,twig,etc.) to routes:
// dummy action that serves index/testview
public function fooAction(){
$vm = new Zend\View\Model\ViewModel();
$vm->setTemplate('index/testview');
return $vm;
}
That index/testview, will be in your module's view templates, not in your public folder.
I think that's a reasonable primer to get you on your way!
Take some time to learn:
http://zf2.readthedocs.io/en/latest/index.html#userguide
Maybe start here:
http://zf2.readthedocs.io/en/latest/in-depth-guide/understanding-routing.html
ZF2 (V3 is coming!) is a beautiful thing, it's worth it.
Good luck.
I am trying out CodeIgniter 2.1.4. I already have a controller for showing static pages which I built using the tutorial in CodeIgnitor documentation. I later set-up my routes like this:
// <http://localhost/> refers to <http://localhost/pages/view/>
$route['default_controller'] = "pages/view";
// <http://localhost/somepage/> refers to <http://localhost/pages/view/somepage/>
$route['(:any)'] = "pages/view/$1";
// .htaccess is already setup to rewrite the url without index.php
Now, I don't have much experience with PHP, and the concepts of URL Rewriting and MVC Architecture are fairly new to me.
Let's say there's are pages called •Home, •About, •Admin and •Contact.
For the pages •Home, •About and •Contact, the Pages controller works right as it should.
But for •Admin page, I want to have a separate controller which determines whether the user has logged in or not, and whether he has admin rights etc. And if he hasn't logged in yet, I should load the Login view instead of the Admin view.
The Pages controller has a fairly simple logic. It checks whether the string in argument, appended with .php and prepended with the views directory, exists as a file or not. If it doesn't show_404(), if it does, load view header-template, then load the page, then load view footer-templat. I'm pretty sure most of you who have worked with CodeIgniter must've seen a similar logic for static pages.
I could do redirect('login') inside my Admin view, but that doesn't seem to work. If I create a separate controller for Admin, how would I access it, while according to routes, every URL gets directed to pages/view controller (line#4 in the above code).
As I've already said, I'm fairly new to this. It might be some retarded mistake that I'm making. Or my whole MVC structure might be inappropriately built. How do I get past this and start worrying about the authentication stuff? Can anyone advise?
$route['default_controller'] = "pages/view";
$route['admin/(:any)'] = "admin/$1"; //(admin controller) with "any" method
$route['(:any)'] = "pages/view/$1";
localhost/poject/admin/edit as example
The problem you are experiencing is simple, you overwrite all controllers by that (:any) it isn't wrong but you need to manualy assign each controller that you want route as normal controller as I posted above.
please note that routes are order dependant and if one (first) is used second one is ignored. "Routes will run in the order they are defined. Higher routes will always take precedence over lower ones."
For authentification please see this post.
I would rather use _remap() and extend CI_Controller to take over my routes instead of having this route $route['(:any)'] = "pages/view/$1"; in routes.php.
remapping
Being new to Cake on PHP, I am trying to work out if I have a URL, what would be the easiest way to find the controller code for it?
The URL on my local machine is something like:
http://foofoofoo.local/protected/admin/org/edit/1
I have worked out that the location of the view for this file is at this location on my machine:
/var/www/MyApp/protected/app/views/org/admin_edit.ctp
I thought what I'd do is do a search throughout the entire codebase for anything referencing admin_edit.ctp. I found two entries, and changed them to see if I had found the point where the view is called, but despite changing the file name on these entries - the app still works when I visit the URL: http://foofoofoo.local/protected/admin/org/edit/1
I just want to see where the admin_edit.ctp file is being called within the site.
URL: http://foofoofoo.local/protected/admin/org/edit/1
This means I can assume you have a added a route in your /app/Config/routes.php. Where this is pointing can not be said since we don't have access to this file.
Why can I assume you have added this to your routes? Because the posted URL is not matching the CakePHP Conventions which clearly states that controllers should be defined in plural. Since the URL will be accessing the Controller directly through the Controller, unless a route has been specified, I know that the OrgController does not exist. Why?
Try Inflector::pluralize('Org'). It will return 'Orgs' to you. And thus meaning the controller should be called OrgsController and you should be accessing this Controller via the following URL.
http://foofoofoo.local/protected/admin/orgs/edit/1
In this OrgsController there should be an action (function) called admin_edit(), because you have prepended the org with Admin, which is a prefix.
It can be possible that the /protected part, is part of the URL as well, but do not know where your main /App is located and what part of the URL is pointing to the /app/webroot/index.php file.
The Views can be found at /app/View/Orgs/*.ctp.
If you are still having trouble finding your files. Please start with the Blog tutorial written by the Cake Community. This tutorial describes all the neat built-in tricks and will get your first app running in no-time. Please read that first!
If you are still having trouble, feel free to update your question and add the /app/Config/routes.php file.
Under Cake 1.3, if your application has an AppController (check if the file app/app_controller.php exists), you can put this code in the beforeFilter method:
debug($this->params);
It will print an array on your app pages when you are in debug mode, with the name of the controller and the action used.
Array
(
...
[controller] => controller_name
[action] => action_name
...
)
If the AppController does not contain any beforeFilter method, you can just create it:
function beforeFilter()
{
debug($this->params);
}
I have encountered an issue using subfolders with Codeigniter + HMVC.
/system/application/modules/welcome/controllers/staff/welcome.php
To access this I have to access it via http://www.app.com/welcome/staff/welcome
Unfortunately this doesn't fit the rest of my URL structure.
How can I remove the first welcome from the URL so the URL is http://www.app.com/staff/welcome
I have tried adding a route within the module:
/system/application/modules/welcome/config/routes.php
like:
$route['staff/welcome'] = "welcome/staff/welcome";
but unfortunately no luck.
Adding this route to the real codeigniter route file works but I feel that adding code external of the modules to get modules to work misses the point of adopting modularisation.
I hope someone is able to help.
Thanks,
Tim
This line in your routes.php is correct:
$route['staff/welcome'] = "welcome/staff/welcome";
You can try to play with the order of your routing rules, and to put the rule for the default controller ($route['default_controller'] = "home";) at the end. I have project with 4 modules and it works fine for me.