Whats the purpose of Index.php in MVC Frameworks? - model-view-controller

I want a good understandable description of index.php in MVC Frameworks... I have worked in Magento and Codeignitor...
In Magento URL's index.php is called front controller but in codeignitor what it is?
Plz clear the concept of index.php in MVC Frameworks?

The index is your entry point from where it will dispatch / route your URL to the appropriate controllers/actions. You don't have to name in index.php though, you can give it whatever name you want, as long as you call the file, it won't be a problem.

In codeigniter index.php is the entry point of the application. Its not a controller. It sets your environment, initializes your config/route/autoload etc. and then loads your requested controller.

Generally, index.php mainly works as a bootstrapper. It initializes all most variables and puts your application in a usable state. Almost all calls are routed through it. If you want you can also hide index.php from your visible path using .htaccess. For example in yii you can use this guide: http://www.yiiframework.com/wiki/214/url-hide-index-php/

Related

How to develop mobile application using CodeIgniter?

I wanted to develop the mobile application using CodeIgniter. Is it possible.
Web application is already built on CodeIgniter
You'll have to create a new controller and add appropriate routes. When I had to do this, I just used a controller that inherited from my primary site controller and added these routes to my routes config (Mine was located in /system/application/config/routes.php. Yours also may look different and this code snippet assumes you have a page function):
$route['mobile/(:any)'] = "site/mobile/page/$1";
$route['mobile'] = "site/mobile/page/home";
Then you'll want to add a rule to your htaccess file to ensure anything going to m.example.com/whatever gets directed to the right path (e.g. /mobile/whatever).
RewriteCond %{HTTP_HOST} (^mobile\.|^m\.)(.*) [NC]
RewriteRule (.*) /index.php/mobile/$1 [L]
From there it should route into your mobile controller. Form me this was in /site/controllers/mobile.php. My primary site controller was /site/controllers/site.php
You'll want to recreate whatever logic you use in your site controller in you mobile one excluding desktop assets and including mobile ones and rendering your pages appropriately. Unfortunately that's about all I understand of the process. It was mostly my coworker's work that got the mobile controller working and I only used it once or twice, but this should work.
Yes, it is posibble. It all depends on your strategy. If you decide to go with Responsive Design, codeigniter makes no difference. If you decide on Adaptive you shoul read the about codeigniter's user-agent library -
https://ellislab.com/codeigniter/user-guide/libraries/user_agent.html
To read about RWD and AWD visit http://www.techrepublic.com/blog/web-designer/what-is-the-difference-between-responsive-vs-adaptive-web-design/

How routing is done in codeigniter?

I could not find the .htaccess file in CodeIgniter framework and i'm wondering how do they do route without it? Or it is somewhere hidden?
There is no .htaccess by default provided with codeigniter. They serve it through the index.php. .htaccess is only used to direct the urls to the index.php. This way codeigniter is working in environments where rewriting isn't allowed. Another way of getting controller and function is by query strings.
Anyway the actual routing is done in system/core/Router.php so you can read the code. Since Codeigniter is open source application that can't be hidden.

Renaming index.php and accessing other pages in Joomla

I have to do some modifications online on my website, and I don't want the users to see those pages. So I renamed index.php to index_orig.php and I put another index.html that show a message (WebSite under construction) for my users.
My problem is that I want to access online to the rest of my pages to check the modifications until satisfaction, but when I try to access the rest of the pages by their whole URL (404 error is shown).
Example : www.mywebsite.com/floder1/pagetarget.php.
Put back index.php.
In your global configuration, set the site to offline and put up a message and a logo etc (assuming you are on 2.5 or 3). You'll be able to login and see the site.
Please keep in mind that in a database driven cms there are not pages in the way that you would think of them in a static html site. Everything gets pushed into the index.php of your template file.
Update the directory default document on whatever webserver you are using. Also update any rewrite rules that may be pointing to index.php

joomla rename component url using htaccess

I'm building an eshop using Joomla 2.5 and a commercial component for a guy who wants to have multiple vendros and I'm stuck on how to change the component's url.
What I want to change is the url that is displayed when the users passes from a link with his mouse.
For instance, the component has a SEF function which rewrites urls and makes them like that:
http://www.site.com/componentname/products/productname-productid-productcategoryid-vendorid.html
http://www.site.com/componentname/catalog/categoryname-categoryid-numberofpage.html
and what I want is to make it:
http://www.site.com/shop/products/productname-productid-productcategoryid-vendorid.html
http://www.site.com/shop/catalog/categoryname-categoryid-numberofpage.html
So when a user passes over a link it will show him the new url. Is this possible with .htaccess and rewrite rules or this can only be done through the component only? I'm asking this as the component is encoded with ioncube so I can't do it myself.
Thanks in advance!
While you can use .htaccess to rewrite any URL it won't work with Joomla! as the SEF URL is created by JRoute which uses a combination of the core route function and the route.php for the component.
The URL segments are used to find the right component to handle the request, so to change the way the URL is built you would have to modify the route.php of the component (and obviously other parts as well).
For more information on how SEF support works, read this on docs.joomla.org

URL Rewrite to remove my controller's name from the url displayed

I have this site
http://cjbuilders.info/welcome/home
and all the links start with
http://cjbuilders.info/welcome
How can I use mod_rewrite to just remove
/welcome/
from the url? This should be an easy one, but i struggle with mod_rewrite.
Do you know about CodeIgniter's URI Routing? Add this into your routes.php config file and it should work just fine:
$route['home'] = 'welcome/home';
This should work, IIRC:
RewriteRule ^/welcome/(.*)$ /$1 [R]
However, guessing a bit about what's going on here, if the reason for this prefix is something like a Java app server deploying an app at a context called "welcome", then the better solution is not to rewrite the URLs but to fix the backend app server to have a null context, i.e. serve at / rather than at /welcome/.
This is because the app server will probably want to generate links to other views of its app, and will reinsert the "welcome": this becomes a pain, and means that all links on your pages will get HTTP redirects when visited (e.g. by search engines). There is no way that the proxying apache server can parse the HTML and tell when that "welcome" should be removed, so best to fix the server that's writing the links in the first place.

Resources